]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx
Salome HOME
0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IMeasureOperations.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_IMeasureOperations.hxx>
25
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOMImpl_MeasureDriver.hxx>
28 #include <GEOMImpl_IMeasure.hxx>
29
30 #include <GEOMAlgo_ShapeInfo.hxx>
31 #include <GEOMAlgo_ShapeInfoFiller.hxx>
32
33 #include <GEOM_Function.hxx>
34 #include <GEOM_PythonDump.hxx>
35
36 #include <utilities.h>
37 #include <OpUtil.hxx>
38 #include <Utils_ExceptHandlers.hxx>
39
40 // OCCT Includes
41 #include <TFunction_DriverTable.hxx>
42 #include <TFunction_Driver.hxx>
43 #include <TFunction_Logbook.hxx>
44 #include <TDF_Tool.hxx>
45
46 #include <BRep_Tool.hxx>
47 #include <BRepAdaptor_Surface.hxx>
48 #include <BRepBndLib.hxx>
49 #include <BRepCheck.hxx>
50 #include <BRepCheck_Result.hxx>
51 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
52 #include <BRepExtrema_DistShapeShape.hxx>
53 #include <BRepGProp.hxx>
54 #include <BRepTools.hxx>
55
56 #include <Bnd_Box.hxx>
57
58 #include <GProp_GProps.hxx>
59 #include <GProp_PrincipalProps.hxx>
60
61 #include <TopAbs.hxx>
62 #include <TopoDS.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <TopoDS_Iterator.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72
73 #include <GeomAbs_SurfaceType.hxx>
74 #include <Geom_Surface.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_SphericalSurface.hxx>
77 #include <Geom_CylindricalSurface.hxx>
78 #include <Geom_ToroidalSurface.hxx>
79 #include <Geom_ConicalSurface.hxx>
80 #include <Geom_SurfaceOfLinearExtrusion.hxx>
81 #include <Geom_SurfaceOfRevolution.hxx>
82 #include <Geom_BezierSurface.hxx>
83 #include <Geom_BSplineSurface.hxx>
84 #include <Geom_RectangularTrimmedSurface.hxx>
85 #include <Geom_OffsetSurface.hxx>
86 #include <Geom_Line.hxx>
87
88 #include <gp_Pln.hxx>
89 #include <gp_Lin.hxx>
90
91 #include <GeomAPI_ProjectPointOnCurve.hxx>
92 #include <GeomLProp_CLProps.hxx>
93 #include <GeomLProp_SLProps.hxx>
94 #include <ShapeAnalysis.hxx>
95 #include <ShapeAnalysis_Surface.hxx>
96
97 #include <Standard_Failure.hxx>
98 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
99
100 #include <BRepClass3d_SolidClassifier.hxx>
101 #include <BRep_Builder.hxx>
102 #include <GeomAPI_IntSS.hxx>
103 #include <Geom_Circle.hxx>
104 #include <Geom_SphericalSurface.hxx>
105 #include <Geom_ToroidalSurface.hxx>
106 #include <ShapeFix_Shape.hxx>
107 #include <TopoDS_Compound.hxx>
108
109
110 //=============================================================================
111 /*!
112  *  Constructor
113  */
114 //=============================================================================
115 GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
116 : GEOM_IOperations(theEngine, theDocID)
117 {
118   MESSAGE("GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations");
119 }
120
121 //=============================================================================
122 /*!
123  *  Destructor
124  */
125 //=============================================================================
126 GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
127 {
128   MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
129 }
130
131 //=============================================================================
132 /*! Get kind and parameters of the given shape.
133  */
134 //=============================================================================
135 GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
136                              (Handle(GEOM_Object) theShape,
137                               Handle(TColStd_HSequenceOfInteger)& theIntegers,
138                               Handle(TColStd_HSequenceOfReal)&    theDoubles)
139 {
140   SetErrorCode(KO);
141   ShapeKind aKind = SK_NO_SHAPE;
142
143   if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
144   else                      theIntegers->Clear();
145
146   if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
147   else                     theDoubles->Clear();
148
149   if (theShape.IsNull())
150     return aKind;
151
152   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
153   if (aRefShape.IsNull()) return aKind;
154
155   TopoDS_Shape aShape = aRefShape->GetValue();
156   if (aShape.IsNull()) return aKind;
157
158   // Call algorithm
159   GEOMAlgo_ShapeInfoFiller aSF;
160   aSF.SetShape(aShape);
161   aSF.Perform();
162   Standard_Integer iErr = aSF.ErrorStatus();
163   if (iErr) {
164     SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
165     return SK_NO_SHAPE;
166   }
167   const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
168
169   // Interprete results
170   TopAbs_ShapeEnum aType = anInfo.Type();
171   switch (aType)
172   {
173   case TopAbs_COMPOUND:
174   case TopAbs_COMPSOLID:
175     {
176       // (+) geompy.kind.COMPOUND     nb_solids nb_faces nb_edges nb_vertices
177       // (+) geompy.kind.COMPSOLID    nb_solids nb_faces nb_edges nb_vertices
178       // ??? "nb_faces" - all faces or only 'standalone' faces?
179       if (aType == TopAbs_COMPOUND)
180         aKind = SK_COMPOUND;
181       else
182         aKind = SK_COMPSOLID;
183
184       //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
185       //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
186       theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
187       theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
188       theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
189       theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
190     }
191     break;
192
193   case TopAbs_SHELL:
194     {
195       // (+) geompy.kind.SHELL  geompy.info.closed   nb_faces nb_edges nb_vertices
196       // (+) geompy.kind.SHELL  geompy.info.unclosed nb_faces nb_edges nb_vertices
197       aKind = SK_SHELL;
198
199       theIntegers->Append((int)anInfo.KindOfClosed());
200
201       theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
202       theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
203       theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
204     }
205     break;
206
207   case TopAbs_WIRE:
208     {
209       // (+) geompy.kind.WIRE  geompy.info.closed   nb_edges nb_vertices
210       // (+) geompy.kind.WIRE  geompy.info.unclosed nb_edges nb_vertices
211       aKind = SK_WIRE;
212
213       theIntegers->Append((int)anInfo.KindOfClosed());
214
215       theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
216       theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
217     }
218     break;
219
220   case TopAbs_SOLID:
221     {
222       aKind = SK_SOLID;
223
224       GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
225       switch (aKN)
226       {
227       case GEOMAlgo_KN_SPHERE:
228         // (+) geompy.kind.SPHERE  xc yc zc  R
229         {
230           aKind = SK_SPHERE;
231
232           gp_Pnt aC = anInfo.Location();
233           theDoubles->Append(aC.X());
234           theDoubles->Append(aC.Y());
235           theDoubles->Append(aC.Z());
236
237           theDoubles->Append(anInfo.Radius1());
238         }
239         break;
240       case GEOMAlgo_KN_CYLINDER:
241         // (+) geompy.kind.CYLINDER  xb yb zb  dx dy dz  R  H
242         {
243           aKind = SK_CYLINDER;
244
245           gp_Pnt aC = anInfo.Location();
246           theDoubles->Append(aC.X());
247           theDoubles->Append(aC.Y());
248           theDoubles->Append(aC.Z());
249
250           gp_Ax3 anAx3 = anInfo.Position();
251           gp_Dir aD = anAx3.Direction();
252           theDoubles->Append(aD.X());
253           theDoubles->Append(aD.Y());
254           theDoubles->Append(aD.Z());
255
256           theDoubles->Append(anInfo.Radius1());
257           theDoubles->Append(anInfo.Height());
258         }
259         break;
260       case GEOMAlgo_KN_BOX:
261         // (+) geompy.kind.BOX  xc yc zc  ax ay az
262         {
263           aKind = SK_BOX;
264
265           gp_Pnt aC = anInfo.Location();
266           theDoubles->Append(aC.X());
267           theDoubles->Append(aC.Y());
268           theDoubles->Append(aC.Z());
269
270           gp_Ax3 anAx3 = anInfo.Position();
271           gp_Dir aD = anAx3.Direction();
272           gp_Dir aX = anAx3.XDirection();
273
274           // ax ay az
275           if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
276               aX.IsParallel(gp::DX(), Precision::Angular())) {
277             theDoubles->Append(anInfo.Length()); // ax'
278             theDoubles->Append(anInfo.Width());  // ay'
279             theDoubles->Append(anInfo.Height()); // az'
280           }
281           else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
282                    aX.IsParallel(gp::DY(), Precision::Angular())) {
283             theDoubles->Append(anInfo.Width());  // ay'
284             theDoubles->Append(anInfo.Length()); // ax'
285             theDoubles->Append(anInfo.Height()); // az'
286           }
287           else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
288                    aX.IsParallel(gp::DZ(), Precision::Angular())) {
289             theDoubles->Append(anInfo.Height()); // az'
290             theDoubles->Append(anInfo.Width());  // ay'
291             theDoubles->Append(anInfo.Length()); // ax'
292           }
293           else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
294                    aX.IsParallel(gp::DY(), Precision::Angular())) {
295             theDoubles->Append(anInfo.Height()); // az'
296             theDoubles->Append(anInfo.Length()); // ax'
297             theDoubles->Append(anInfo.Width());  // ay'
298           }
299           else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
300                    aX.IsParallel(gp::DZ(), Precision::Angular())) {
301             theDoubles->Append(anInfo.Width());  // ay'
302             theDoubles->Append(anInfo.Height()); // az'
303             theDoubles->Append(anInfo.Length()); // ax'
304           }
305           else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
306                    aX.IsParallel(gp::DX(), Precision::Angular())) {
307             theDoubles->Append(anInfo.Length()); // ax'
308             theDoubles->Append(anInfo.Height()); // az'
309             theDoubles->Append(anInfo.Width());  // ay'
310           }
311           else {
312             // (+) geompy.kind.ROTATED_BOX  xo yo zo  zx zy zz  xx xy xz  ax ay az
313             aKind = SK_ROTATED_BOX;
314
315             // Direction and XDirection
316             theDoubles->Append(aD.X());
317             theDoubles->Append(aD.Y());
318             theDoubles->Append(aD.Z());
319
320             theDoubles->Append(aX.X());
321             theDoubles->Append(aX.Y());
322             theDoubles->Append(aX.Z());
323
324             // ax ay az
325             theDoubles->Append(anInfo.Length());
326             theDoubles->Append(anInfo.Width());
327             theDoubles->Append(anInfo.Height());
328           }
329         }
330         break;
331       case GEOMAlgo_KN_TORUS:
332         // (+) geompy.kind.TORUS  xc yc zc  dx dy dz  R_1 R_2
333         {
334           aKind = SK_TORUS;
335
336           gp_Pnt aO = anInfo.Location();
337           theDoubles->Append(aO.X());
338           theDoubles->Append(aO.Y());
339           theDoubles->Append(aO.Z());
340
341           gp_Ax3 anAx3 = anInfo.Position();
342           gp_Dir aD = anAx3.Direction();
343           theDoubles->Append(aD.X());
344           theDoubles->Append(aD.Y());
345           theDoubles->Append(aD.Z());
346
347           theDoubles->Append(anInfo.Radius1());
348           theDoubles->Append(anInfo.Radius2());
349         }
350         break;
351       case GEOMAlgo_KN_CONE:
352         // (+) geompy.kind.CONE  xb yb zb  dx dy dz  R_1 R_2  H
353         {
354           aKind = SK_CONE;
355
356           gp_Pnt aO = anInfo.Location();
357           theDoubles->Append(aO.X());
358           theDoubles->Append(aO.Y());
359           theDoubles->Append(aO.Z());
360
361           gp_Ax3 anAx3 = anInfo.Position();
362           gp_Dir aD = anAx3.Direction();
363           theDoubles->Append(aD.X());
364           theDoubles->Append(aD.Y());
365           theDoubles->Append(aD.Z());
366
367           theDoubles->Append(anInfo.Radius1());
368           theDoubles->Append(anInfo.Radius2());
369           theDoubles->Append(anInfo.Height());
370         }
371         break;
372       case GEOMAlgo_KN_POLYHEDRON:
373         // (+) geompy.kind.POLYHEDRON  nb_faces nb_edges nb_vertices
374         {
375           aKind = SK_POLYHEDRON;
376
377           theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
378           theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
379           theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
380         }
381         break;
382       default:
383         // (+) geompy.kind.SOLID  nb_faces nb_edges nb_vertices
384         {
385           theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
386           theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
387           theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
388         }
389       }
390     }
391     break;
392
393   case TopAbs_FACE:
394     {
395       aKind = SK_FACE;
396
397       GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
398       switch (aKN) {
399       case GEOMAlgo_KN_SPHERE:
400         // (+) geompy.kind.SPHERE2D  xc yc zc  R
401         {
402           aKind = SK_SPHERE2D;
403
404           gp_Pnt aC = anInfo.Location();
405           theDoubles->Append(aC.X());
406           theDoubles->Append(aC.Y());
407           theDoubles->Append(aC.Z());
408
409           theDoubles->Append(anInfo.Radius1());
410         }
411         break;
412       case GEOMAlgo_KN_CYLINDER:
413         // (+) geompy.kind.CYLINDER2D  xb yb zb  dx dy dz  R  H
414         {
415           aKind = SK_CYLINDER2D;
416
417           gp_Pnt aO = anInfo.Location();
418           theDoubles->Append(aO.X());
419           theDoubles->Append(aO.Y());
420           theDoubles->Append(aO.Z());
421
422           gp_Ax3 anAx3 = anInfo.Position();
423           gp_Dir aD = anAx3.Direction();
424           theDoubles->Append(aD.X());
425           theDoubles->Append(aD.Y());
426           theDoubles->Append(aD.Z());
427
428           theDoubles->Append(anInfo.Radius1());
429           theDoubles->Append(anInfo.Height());
430         }
431         break;
432       case GEOMAlgo_KN_TORUS:
433         // (+) geompy.kind.TORUS2D  xc yc zc  dx dy dz  R_1 R_2
434         {
435           aKind = SK_TORUS2D;
436
437           gp_Pnt aO = anInfo.Location();
438           theDoubles->Append(aO.X());
439           theDoubles->Append(aO.Y());
440           theDoubles->Append(aO.Z());
441
442           gp_Ax3 anAx3 = anInfo.Position();
443           gp_Dir aD = anAx3.Direction();
444           theDoubles->Append(aD.X());
445           theDoubles->Append(aD.Y());
446           theDoubles->Append(aD.Z());
447
448           theDoubles->Append(anInfo.Radius1());
449           theDoubles->Append(anInfo.Radius2());
450         }
451         break;
452       case GEOMAlgo_KN_CONE:
453         // (+) geompy.kind.CONE2D  xc yc zc  dx dy dz  R_1 R_2  H
454         {
455           aKind = SK_CONE2D;
456
457           gp_Pnt aO = anInfo.Location();
458           theDoubles->Append(aO.X());
459           theDoubles->Append(aO.Y());
460           theDoubles->Append(aO.Z());
461
462           gp_Ax3 anAx3 = anInfo.Position();
463           gp_Dir aD = anAx3.Direction();
464           theDoubles->Append(aD.X());
465           theDoubles->Append(aD.Y());
466           theDoubles->Append(aD.Z());
467
468           theDoubles->Append(anInfo.Radius1());
469           theDoubles->Append(anInfo.Radius2());
470           theDoubles->Append(anInfo.Height());
471         }
472         break;
473       case GEOMAlgo_KN_DISKCIRCLE:
474         // (+) geompy.kind.DISK_CIRCLE  xc yc zc  dx dy dz  R
475         {
476           aKind = SK_DISK_CIRCLE;
477
478           gp_Pnt aC = anInfo.Location();
479           theDoubles->Append(aC.X());
480           theDoubles->Append(aC.Y());
481           theDoubles->Append(aC.Z());
482
483           gp_Ax3 anAx3 = anInfo.Position();
484           gp_Dir aD = anAx3.Direction();
485           theDoubles->Append(aD.X());
486           theDoubles->Append(aD.Y());
487           theDoubles->Append(aD.Z());
488
489           theDoubles->Append(anInfo.Radius1());
490         }
491         break;
492       case GEOMAlgo_KN_DISKELLIPSE:
493         // (+) geompy.kind.DISK_ELLIPSE  xc yc zc  dx dy dz  R_1 R_2
494         {
495           aKind = SK_DISK_ELLIPSE;
496
497           gp_Pnt aC = anInfo.Location();
498           theDoubles->Append(aC.X());
499           theDoubles->Append(aC.Y());
500           theDoubles->Append(aC.Z());
501
502           gp_Ax3 anAx3 = anInfo.Position();
503           gp_Dir aD = anAx3.Direction();
504           theDoubles->Append(aD.X());
505           theDoubles->Append(aD.Y());
506           theDoubles->Append(aD.Z());
507
508           theDoubles->Append(anInfo.Radius1());
509           theDoubles->Append(anInfo.Radius2());
510         }
511         break;
512       case GEOMAlgo_KN_RECTANGLE:
513       case GEOMAlgo_KN_TRIANGLE:
514       case GEOMAlgo_KN_QUADRANGLE:
515       case GEOMAlgo_KN_POLYGON:
516         // (+) geompy.kind.POLYGON  xo yo zo  dx dy dz  nb_edges nb_vertices
517         {
518           aKind = SK_POLYGON;
519
520           gp_Pnt aO = anInfo.Location();
521           theDoubles->Append(aO.X());
522           theDoubles->Append(aO.Y());
523           theDoubles->Append(aO.Z());
524
525           gp_Ax3 anAx3 = anInfo.Position();
526           gp_Dir aD = anAx3.Direction();
527           theDoubles->Append(aD.X());
528           theDoubles->Append(aD.Y());
529           theDoubles->Append(aD.Z());
530
531           theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
532           theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
533         }
534         break;
535       case GEOMAlgo_KN_PLANE: // infinite
536         // (+) geompy.kind.PLANE  xo yo zo  dx dy dz
537         {
538           aKind = SK_PLANE;
539
540           gp_Pnt aC = anInfo.Location();
541           theDoubles->Append(aC.X());
542           theDoubles->Append(aC.Y());
543           theDoubles->Append(aC.Z());
544
545           gp_Ax3 anAx3 = anInfo.Position();
546           gp_Dir aD = anAx3.Direction();
547           theDoubles->Append(aD.X());
548           theDoubles->Append(aD.Y());
549           theDoubles->Append(aD.Z());
550         }
551         break;
552       default:
553         if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
554           // (+) geompy.kind.PLANAR  xo yo zo  dx dy dz  nb_edges nb_vertices
555
556           aKind = SK_PLANAR;
557
558           gp_Pnt aC = anInfo.Location();
559           theDoubles->Append(aC.X());
560           theDoubles->Append(aC.Y());
561           theDoubles->Append(aC.Z());
562
563           gp_Ax3 anAx3 = anInfo.Position();
564           gp_Dir aD = anAx3.Direction();
565           theDoubles->Append(aD.X());
566           theDoubles->Append(aD.Y());
567           theDoubles->Append(aD.Z());
568
569           theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
570           theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
571         }
572         else {
573           // ??? geompy.kind.FACE  nb_edges nb_vertices _surface_type_id_
574           // (+) geompy.kind.FACE  nb_edges nb_vertices
575
576           theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
577           theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
578         }
579       }
580     }
581     break;
582
583   case TopAbs_EDGE:
584     {
585       aKind = SK_EDGE;
586
587       GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
588       switch (aKN) {
589       case GEOMAlgo_KN_CIRCLE:
590         {
591           // (+) geompy.kind.CIRCLE  xc yc zc  dx dy dz  R
592           aKind = SK_CIRCLE;
593
594           gp_Pnt aC = anInfo.Location();
595           theDoubles->Append(aC.X());
596           theDoubles->Append(aC.Y());
597           theDoubles->Append(aC.Z());
598
599           gp_Ax3 anAx3 = anInfo.Position();
600           gp_Dir aD = anAx3.Direction();
601           theDoubles->Append(aD.X());
602           theDoubles->Append(aD.Y());
603           theDoubles->Append(aD.Z());
604
605           theDoubles->Append(anInfo.Radius1());
606         }
607         break;
608       case GEOMAlgo_KN_ARCCIRCLE:
609         {
610           // (+) geompy.kind.ARC_CIRCLE  xc yc zc  dx dy dz  R  x1 y1 z1  x2 y2 z2
611           aKind = SK_ARC_CIRCLE;
612
613           gp_Pnt aC = anInfo.Location();
614           theDoubles->Append(aC.X());
615           theDoubles->Append(aC.Y());
616           theDoubles->Append(aC.Z());
617
618           gp_Ax3 anAx3 = anInfo.Position();
619           gp_Dir aD = anAx3.Direction();
620           theDoubles->Append(aD.X());
621           theDoubles->Append(aD.Y());
622           theDoubles->Append(aD.Z());
623
624           theDoubles->Append(anInfo.Radius1());
625
626           gp_Pnt aP1 = anInfo.Pnt1();
627           theDoubles->Append(aP1.X());
628           theDoubles->Append(aP1.Y());
629           theDoubles->Append(aP1.Z());
630
631           gp_Pnt aP2 = anInfo.Pnt2();
632           theDoubles->Append(aP2.X());
633           theDoubles->Append(aP2.Y());
634           theDoubles->Append(aP2.Z());
635         }
636         break;
637       case GEOMAlgo_KN_ELLIPSE:
638         {
639           // (+) geompy.kind.ELLIPSE  xc yc zc  dx dy dz  R_1 R_2
640           aKind = SK_ELLIPSE;
641
642           gp_Pnt aC = anInfo.Location();
643           theDoubles->Append(aC.X());
644           theDoubles->Append(aC.Y());
645           theDoubles->Append(aC.Z());
646
647           gp_Ax3 anAx3 = anInfo.Position();
648           gp_Dir aD = anAx3.Direction();
649           theDoubles->Append(aD.X());
650           theDoubles->Append(aD.Y());
651           theDoubles->Append(aD.Z());
652
653           theDoubles->Append(anInfo.Radius1());
654           theDoubles->Append(anInfo.Radius2());
655         }
656         break;
657       case GEOMAlgo_KN_ARCELLIPSE:
658         {
659           // (+) geompy.kind.ARC_ELLIPSE  xc yc zc  dx dy dz  R_1 R_2  x1 y1 z1  x2 y2 z2
660           aKind = SK_ARC_ELLIPSE;
661
662           gp_Pnt aC = anInfo.Location();
663           theDoubles->Append(aC.X());
664           theDoubles->Append(aC.Y());
665           theDoubles->Append(aC.Z());
666
667           gp_Ax3 anAx3 = anInfo.Position();
668           gp_Dir aD = anAx3.Direction();
669           theDoubles->Append(aD.X());
670           theDoubles->Append(aD.Y());
671           theDoubles->Append(aD.Z());
672
673           theDoubles->Append(anInfo.Radius1());
674           theDoubles->Append(anInfo.Radius2());
675
676           gp_Pnt aP1 = anInfo.Pnt1();
677           theDoubles->Append(aP1.X());
678           theDoubles->Append(aP1.Y());
679           theDoubles->Append(aP1.Z());
680
681           gp_Pnt aP2 = anInfo.Pnt2();
682           theDoubles->Append(aP2.X());
683           theDoubles->Append(aP2.Y());
684           theDoubles->Append(aP2.Z());
685         }
686         break;
687       case GEOMAlgo_KN_LINE:
688         {
689           // ??? geompy.kind.LINE  x1 y1 z1  x2 y2 z2
690           // (+) geompy.kind.LINE  x1 y1 z1  dx dy dz
691           aKind = SK_LINE;
692
693           gp_Pnt aO = anInfo.Location();
694           theDoubles->Append(aO.X());
695           theDoubles->Append(aO.Y());
696           theDoubles->Append(aO.Z());
697
698           gp_Dir aD = anInfo.Direction();
699           theDoubles->Append(aD.X());
700           theDoubles->Append(aD.Y());
701           theDoubles->Append(aD.Z());
702         }
703         break;
704       case GEOMAlgo_KN_SEGMENT:
705         {
706           // (+) geompy.kind.SEGMENT  x1 y1 z1  x2 y2 z2
707           aKind = SK_SEGMENT;
708
709           gp_Pnt aP1 = anInfo.Pnt1();
710           theDoubles->Append(aP1.X());
711           theDoubles->Append(aP1.Y());
712           theDoubles->Append(aP1.Z());
713
714           gp_Pnt aP2 = anInfo.Pnt2();
715           theDoubles->Append(aP2.X());
716           theDoubles->Append(aP2.Y());
717           theDoubles->Append(aP2.Z());
718         }
719         break;
720       default:
721         // ??? geompy.kind.EDGE  nb_vertices _curve_type_id_
722         // (+) geompy.kind.EDGE  nb_vertices
723         theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
724       }
725     }
726     break;
727
728   case TopAbs_VERTEX:
729     {
730       // (+) geompy.kind.VERTEX  x y z
731       aKind = SK_VERTEX;
732
733       gp_Pnt aP = anInfo.Location();
734       theDoubles->Append(aP.X());
735       theDoubles->Append(aP.Y());
736       theDoubles->Append(aP.Z());
737     }
738     break;
739   }
740
741   SetErrorCode(OK);
742   return aKind;
743 }
744
745 //=============================================================================
746 /*! Get LCS, corresponding to the given shape.
747  *  Origin of the LCS is situated at the shape's center of mass.
748  *  Axes of the LCS are obtained from shape's location or,
749  *  if the shape is a planar face, from position of its plane.
750  */
751 //=============================================================================
752 gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
753 {
754   gp_Ax3 aResult;
755
756   if (theShape.IsNull())
757     return aResult;
758
759   // Axes
760   aResult.Transform(theShape.Location().Transformation());
761   if (theShape.ShapeType() == TopAbs_FACE) {
762     Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
763     if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
764       Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
765       gp_Pln aPln = aGPlane->Pln();
766       aResult = aPln.Position();
767     }
768   }
769
770   // Origin
771   gp_Pnt aPnt;
772   if (theShape.ShapeType() == TopAbs_VERTEX) {
773     aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
774   }
775   else {
776     GProp_GProps aSystem;
777     if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
778       BRepGProp::LinearProperties(theShape, aSystem);
779     else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
780       BRepGProp::SurfaceProperties(theShape, aSystem);
781     else
782       BRepGProp::VolumeProperties(theShape, aSystem);
783
784     aPnt = aSystem.CentreOfMass();
785   }
786
787   aResult.SetLocation(aPnt);
788
789   return aResult;
790 }
791
792 //=============================================================================
793 /*!
794  *  GetPosition
795  */
796 //=============================================================================
797 void GEOMImpl_IMeasureOperations::GetPosition
798                    (Handle(GEOM_Object) theShape,
799                     Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
800                     Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
801                     Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
802 {
803   SetErrorCode(KO);
804
805   //Set default values: global CS
806   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
807   Zz = Xx = 1.;
808
809   if (theShape.IsNull()) return;
810
811   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
812   if (aRefShape.IsNull()) return;
813
814   TopoDS_Shape aShape = aRefShape->GetValue();
815   if (aShape.IsNull()) {
816     SetErrorCode("The Objects has NULL Shape");
817     return;
818   }
819
820   try {
821 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
822     OCC_CATCH_SIGNALS;
823 #endif
824
825     gp_Ax3 anAx3 = GetPosition(aShape);
826
827     gp_Pnt anOri = anAx3.Location();
828     gp_Dir aDirZ = anAx3.Direction();
829     gp_Dir aDirX = anAx3.XDirection();
830
831     // Output values
832     anOri.Coord(Ox, Oy, Oz);
833     aDirZ.Coord(Zx, Zy, Zz);
834     aDirX.Coord(Xx, Xy, Xz);
835   }
836   catch (Standard_Failure) {
837     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
838     SetErrorCode(aFail->GetMessageString());
839     return;
840   }
841
842   SetErrorCode(OK);
843 }
844
845 //=============================================================================
846 /*!
847  *  GetCentreOfMass
848  */
849 //=============================================================================
850 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetCentreOfMass
851                                                 (Handle(GEOM_Object) theShape)
852 {
853   SetErrorCode(KO);
854
855   if (theShape.IsNull()) return NULL;
856
857   //Add a new CentreOfMass object
858   Handle(GEOM_Object) aCDG = GetEngine()->AddObject(GetDocID(), GEOM_CDG);
859
860   //Add a new CentreOfMass function
861   Handle(GEOM_Function) aFunction =
862     aCDG->AddFunction(GEOMImpl_MeasureDriver::GetID(), CDG_MEASURE);
863   if (aFunction.IsNull()) return NULL;
864
865   //Check if the function is set correctly
866   if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
867
868   GEOMImpl_IMeasure aCI (aFunction);
869
870   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
871   if (aRefShape.IsNull()) return NULL;
872
873   aCI.SetBase(aRefShape);
874
875   //Compute the CentreOfMass value
876   try {
877 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
878     OCC_CATCH_SIGNALS;
879 #endif
880     if (!GetSolver()->ComputeFunction(aFunction)) {
881       SetErrorCode("Measure driver failed to compute centre of mass");
882       return NULL;
883     }
884   }
885   catch (Standard_Failure) {
886     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
887     SetErrorCode(aFail->GetMessageString());
888     return NULL;
889   }
890
891   //Make a Python command
892   GEOM::TPythonDump(aFunction) << aCDG << " = geompy.MakeCDG(" << theShape << ")";
893
894   SetErrorCode(OK);
895   return aCDG;
896 }
897
898 //=============================================================================
899 /*!
900  *  GetNormal
901  */
902 //=============================================================================
903 Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
904                                          (Handle(GEOM_Object) theFace,
905                                           Handle(GEOM_Object) theOptionalPoint)
906 {
907   SetErrorCode(KO);
908
909   if (theFace.IsNull()) return NULL;
910
911   //Add a new Normale object
912   Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
913
914   //Add a new Normale function
915   Handle(GEOM_Function) aFunction =
916     aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
917   if (aFunction.IsNull()) return NULL;
918
919   //Check if the function is set correctly
920   if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
921
922   GEOMImpl_IMeasure aCI (aFunction);
923
924   Handle(GEOM_Function) aFace = theFace->GetLastFunction();
925   if (aFace.IsNull()) return NULL;
926
927   aCI.SetBase(aFace);
928
929   if (!theOptionalPoint.IsNull()) {
930     Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
931     aCI.SetPoint(anOptPnt);
932   }
933
934   //Compute the Normale value
935   try {
936 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
937     OCC_CATCH_SIGNALS;
938 #endif
939     if (!GetSolver()->ComputeFunction(aFunction)) {
940       SetErrorCode("Measure driver failed to compute normake of face");
941       return NULL;
942     }
943   }
944   catch (Standard_Failure) {
945     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
946     SetErrorCode(aFail->GetMessageString());
947     return NULL;
948   }
949
950   //Make a Python command
951   GEOM::TPythonDump pd (aFunction);
952   pd << aNorm << " = geompy.GetNormal(" << theFace;
953   if (!theOptionalPoint.IsNull()) {
954     pd << ", " << theOptionalPoint;
955   }
956   pd << ")";
957
958   SetErrorCode(OK);
959   return aNorm;
960 }
961
962 //=============================================================================
963 /*!
964  *  GetBasicProperties
965  */
966 //=============================================================================
967 void GEOMImpl_IMeasureOperations::GetBasicProperties (Handle(GEOM_Object) theShape,
968                                                       Standard_Real& theLength,
969                                                       Standard_Real& theSurfArea,
970                                                       Standard_Real& theVolume)
971 {
972   SetErrorCode(KO);
973
974   if (theShape.IsNull()) return;
975
976   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
977   if (aRefShape.IsNull()) return;
978
979   TopoDS_Shape aShape = aRefShape->GetValue();
980   if (aShape.IsNull()) {
981     SetErrorCode("The Objects has NULL Shape");
982     return;
983   }
984
985   //Compute the parameters
986   GProp_GProps LProps, SProps;
987   try {
988 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
989     OCC_CATCH_SIGNALS;
990 #endif
991     BRepGProp::LinearProperties(aShape, LProps);
992     theLength = LProps.Mass();
993
994     BRepGProp::SurfaceProperties(aShape, SProps);
995     theSurfArea = SProps.Mass();
996
997     theVolume = 0.0;
998     if (aShape.ShapeType() < TopAbs_SHELL) {
999       for (TopExp_Explorer Exp (aShape, TopAbs_SOLID); Exp.More(); Exp.Next()) {
1000         GProp_GProps VProps;
1001         BRepGProp::VolumeProperties(Exp.Current(), VProps);
1002         theVolume += VProps.Mass();
1003       }
1004     }
1005   }
1006   catch (Standard_Failure) {
1007     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1008     SetErrorCode(aFail->GetMessageString());
1009     return;
1010   }
1011
1012   SetErrorCode(OK);
1013 }
1014
1015 //=============================================================================
1016 /*!
1017  *  GetInertia
1018  */
1019 //=============================================================================
1020 void GEOMImpl_IMeasureOperations::GetInertia
1021                    (Handle(GEOM_Object) theShape,
1022                     Standard_Real& I11, Standard_Real& I12, Standard_Real& I13,
1023                     Standard_Real& I21, Standard_Real& I22, Standard_Real& I23,
1024                     Standard_Real& I31, Standard_Real& I32, Standard_Real& I33,
1025                     Standard_Real& Ix , Standard_Real& Iy , Standard_Real& Iz)
1026 {
1027   SetErrorCode(KO);
1028
1029   if (theShape.IsNull()) return;
1030
1031   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1032   if (aRefShape.IsNull()) return;
1033
1034   TopoDS_Shape aShape = aRefShape->GetValue();
1035   if (aShape.IsNull()) {
1036     SetErrorCode("The Objects has NULL Shape");
1037     return;
1038   }
1039
1040   //Compute the parameters
1041   GProp_GProps System;
1042
1043   try {
1044 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1045     OCC_CATCH_SIGNALS;
1046 #endif
1047     if (aShape.ShapeType() == TopAbs_VERTEX ||
1048         aShape.ShapeType() == TopAbs_EDGE ||
1049         aShape.ShapeType() == TopAbs_WIRE) {
1050       BRepGProp::LinearProperties(aShape, System);
1051     } else if (aShape.ShapeType() == TopAbs_FACE ||
1052                aShape.ShapeType() == TopAbs_SHELL) {
1053       BRepGProp::SurfaceProperties(aShape, System);
1054     } else {
1055       BRepGProp::VolumeProperties(aShape, System);
1056     }
1057     gp_Mat I = System.MatrixOfInertia();
1058
1059     I11 = I(1,1);
1060     I12 = I(1,2);
1061     I13 = I(1,3);
1062
1063     I21 = I(2,1);
1064     I22 = I(2,2);
1065     I23 = I(2,3);
1066
1067     I31 = I(3,1);
1068     I32 = I(3,2);
1069     I33 = I(3,3);
1070
1071     GProp_PrincipalProps Pr = System.PrincipalProperties();
1072     Pr.Moments(Ix,Iy,Iz);
1073   }
1074   catch (Standard_Failure) {
1075     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1076     SetErrorCode(aFail->GetMessageString());
1077     return;
1078   }
1079
1080   SetErrorCode(OK);
1081 }
1082
1083 //=============================================================================
1084 /*!
1085  *  GetBoundingBox
1086  */
1087 //=============================================================================
1088 void GEOMImpl_IMeasureOperations::GetBoundingBox
1089                                      (Handle(GEOM_Object) theShape,
1090                                       Standard_Real& Xmin, Standard_Real& Xmax,
1091                                       Standard_Real& Ymin, Standard_Real& Ymax,
1092                                       Standard_Real& Zmin, Standard_Real& Zmax)
1093 {
1094   SetErrorCode(KO);
1095
1096   if (theShape.IsNull()) return;
1097
1098   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1099   if (aRefShape.IsNull()) return;
1100
1101   TopoDS_Shape aShape = aRefShape->GetValue();
1102   if (aShape.IsNull()) {
1103     SetErrorCode("The Objects has NULL Shape");
1104     return;
1105   }
1106
1107   //Compute the parameters
1108   Bnd_Box B;
1109
1110   try {
1111 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1112     OCC_CATCH_SIGNALS;
1113 #endif
1114     BRepBndLib::Add(aShape, B);
1115     B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
1116   }
1117   catch (Standard_Failure) {
1118     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1119     SetErrorCode(aFail->GetMessageString());
1120     return;
1121   }
1122
1123   SetErrorCode(OK);
1124 }
1125
1126 //=============================================================================
1127 /*!
1128  *  GetTolerance
1129  */
1130 //=============================================================================
1131 void GEOMImpl_IMeasureOperations::GetTolerance
1132                                (Handle(GEOM_Object) theShape,
1133                                 Standard_Real& FaceMin, Standard_Real& FaceMax,
1134                                 Standard_Real& EdgeMin, Standard_Real& EdgeMax,
1135                                 Standard_Real& VertMin, Standard_Real& VertMax)
1136 {
1137   SetErrorCode(KO);
1138
1139   if (theShape.IsNull()) return;
1140
1141   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1142   if (aRefShape.IsNull()) return;
1143
1144   TopoDS_Shape aShape = aRefShape->GetValue();
1145   if (aShape.IsNull()) {
1146     SetErrorCode("The Objects has NULL Shape");
1147     return;
1148   }
1149
1150   //Compute the parameters
1151   Standard_Real T;
1152   FaceMin = EdgeMin = VertMin = RealLast();
1153   FaceMax = EdgeMax = VertMax = -RealLast();
1154
1155   try {
1156 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1157     OCC_CATCH_SIGNALS;
1158 #endif
1159     for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
1160       TopoDS_Face Face = TopoDS::Face(ExF.Current());
1161       T = BRep_Tool::Tolerance(Face);
1162       if (T > FaceMax)
1163         FaceMax = T;
1164       if (T < FaceMin)
1165         FaceMin = T;
1166     }
1167     for (TopExp_Explorer ExE (aShape, TopAbs_EDGE); ExE.More(); ExE.Next()) {
1168       TopoDS_Edge Edge = TopoDS::Edge(ExE.Current());
1169       T = BRep_Tool::Tolerance(Edge);
1170       if (T > EdgeMax)
1171         EdgeMax = T;
1172       if (T < EdgeMin)
1173         EdgeMin = T;
1174     }
1175     for (TopExp_Explorer ExV (aShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
1176       TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
1177       T = BRep_Tool::Tolerance(Vertex);
1178       if (T > VertMax)
1179         VertMax = T;
1180       if (T < VertMin)
1181         VertMin = T;
1182     }
1183   }
1184   catch (Standard_Failure) {
1185     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1186     SetErrorCode(aFail->GetMessageString());
1187     return;
1188   }
1189
1190   SetErrorCode(OK);
1191 }
1192
1193 //=============================================================================
1194 /*!
1195  *  CheckShape
1196  */
1197 //=============================================================================
1198 bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object)      theShape,
1199                                               const Standard_Boolean   theIsCheckGeom,
1200                                               TCollection_AsciiString& theDump)
1201 {
1202   SetErrorCode(KO);
1203
1204   if (theShape.IsNull()) return false;
1205
1206   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1207   if (aRefShape.IsNull()) return false;
1208
1209   TopoDS_Shape aShape = aRefShape->GetValue();
1210   if (aShape.IsNull()) {
1211     SetErrorCode("The Objects has NULL Shape");
1212     return false;
1213   }
1214
1215   //Compute the parameters
1216   bool isValid = false;
1217   try {
1218 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1219     OCC_CATCH_SIGNALS;
1220 #endif
1221     BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
1222     if (ana.IsValid()) {
1223       theDump.Clear();
1224       isValid = true;
1225     } else {
1226       StructuralDump(ana, aShape, theDump);
1227     }
1228   }
1229   catch (Standard_Failure) {
1230     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1231     SetErrorCode(aFail->GetMessageString());
1232     return false;
1233   }
1234
1235   SetErrorCode(OK);
1236   return isValid;
1237 }
1238
1239 //=============================================================================
1240 /*!
1241  *  WhatIs
1242  */
1243 //=============================================================================
1244 TCollection_AsciiString GEOMImpl_IMeasureOperations::WhatIs (Handle(GEOM_Object) theShape)
1245 {
1246   SetErrorCode(KO);
1247
1248   TCollection_AsciiString Astr;
1249
1250   if (theShape.IsNull()) return Astr;
1251
1252   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1253   if (aRefShape.IsNull()) return Astr;
1254
1255   TopoDS_Shape aShape = aRefShape->GetValue();
1256   if (aShape.IsNull()) {
1257     SetErrorCode("The Objects has NULL Shape");
1258     return Astr;
1259   }
1260
1261   //Compute the parameters
1262   if (aShape.ShapeType() == TopAbs_EDGE) {
1263     if (BRep_Tool::Degenerated(TopoDS::Edge(aShape))) {
1264       Astr = Astr + " It is a degenerated edge \n";
1265     }
1266   }
1267
1268   Astr = Astr + " Number of sub-shapes : \n";
1269
1270   try {
1271 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1272     OCC_CATCH_SIGNALS;
1273 #endif
1274     int iType, nbTypes [TopAbs_SHAPE];
1275     for (iType = 0; iType < TopAbs_SHAPE; ++iType)
1276       nbTypes[iType] = 0;
1277     nbTypes[aShape.ShapeType()]++;
1278
1279     TopTools_MapOfShape aMapOfShape;
1280     aMapOfShape.Add(aShape);
1281     TopTools_ListOfShape aListOfShape;
1282     aListOfShape.Append(aShape);
1283
1284     TopTools_ListIteratorOfListOfShape itL (aListOfShape);
1285     for (; itL.More(); itL.Next()) {
1286       TopoDS_Iterator it (itL.Value());
1287       for (; it.More(); it.Next()) {
1288         TopoDS_Shape s = it.Value();
1289         if (aMapOfShape.Add(s)) {
1290           aListOfShape.Append(s);
1291           nbTypes[s.ShapeType()]++;
1292         }
1293       }
1294     }
1295
1296     Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
1297     Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
1298     Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
1299     Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
1300     Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
1301     Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
1302     Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
1303     Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
1304     Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
1305   }
1306   catch (Standard_Failure) {
1307     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1308     SetErrorCode(aFail->GetMessageString());
1309     return Astr;
1310   }
1311
1312   SetErrorCode(OK);
1313   return Astr;
1314 }
1315
1316
1317 //=======================================================================
1318 //function : CheckSingularCase
1319 //purpose  : auxilary for GetMinDistance()
1320 //           workaround for bugs 19899, 19908 and 19910 from Mantis
1321 //=======================================================================
1322 static double CheckSingularCase(const TopoDS_Shape& aSh1,
1323                                 const TopoDS_Shape& aSh2,
1324                                 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
1325 {
1326   bool IsChange1 = false;
1327   double AddDist1 = 0.0;
1328   TopExp_Explorer anExp;
1329   TopoDS_Shape tmpSh1, tmpSh2;
1330   int nbf = 0;
1331   for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1332     nbf++;
1333     tmpSh1 = anExp.Current();
1334   }
1335   if(nbf==1) {
1336     TopoDS_Shape sh = aSh1;
1337     while(sh.ShapeType()==TopAbs_COMPOUND) {
1338       TopoDS_Iterator it(sh);
1339       sh = it.Value();
1340     }
1341     Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1342     if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1343         S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1344       if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1345         // non solid case
1346         double U1,U2,V1,V2;
1347         // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
1348         //S->Bounds(U1,U2,V1,V2); changed by
1349         ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(tmpSh1),U1,U2,V1,V2);
1350         // end of changes for 020677 (dmv)
1351         Handle(Geom_RectangularTrimmedSurface) TrS1 = 
1352           new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1353         Handle(Geom_RectangularTrimmedSurface) TrS2 = 
1354           new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1355         BRep_Builder B;
1356         TopoDS_Face F1,F2;
1357         TopoDS_Compound Comp;
1358         B.MakeCompound(Comp);
1359         B.MakeFace(F1,TrS1,1.e-7);
1360         B.Add(Comp,F1);
1361         B.MakeFace(F2,TrS2,1.e-7);
1362         B.Add(Comp,F2);
1363         Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1364         sfs->Init(Comp);
1365         sfs->SetPrecision(1.e-6);
1366         sfs->SetMaxTolerance(1.0);
1367         sfs->Perform();
1368         tmpSh1 = sfs->Shape();
1369         IsChange1 = true;
1370       }
1371       else {
1372         if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1373           Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1374           gp_Pnt PC = SS->Location();
1375           BRep_Builder B;
1376           TopoDS_Vertex V;
1377           B.MakeVertex(V,PC,1.e-7);
1378           tmpSh1 = V;
1379           AddDist1 = SS->Radius();
1380           IsChange1 = true;
1381         }
1382         else {
1383           Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1384           gp_Ax3 ax3 = TS->Position();
1385           Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1386           BRep_Builder B;
1387           TopoDS_Edge E;
1388           B.MakeEdge(E,C,1.e-7);
1389           tmpSh1 = E;
1390           AddDist1 = TS->MinorRadius();
1391           IsChange1 = true;
1392         }
1393       }
1394     }
1395     else
1396       tmpSh1 = aSh1;
1397   }
1398   else
1399     tmpSh1 = aSh1;
1400   bool IsChange2 = false;
1401   double AddDist2 = 0.0;
1402   nbf = 0;
1403   for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1404     nbf++;
1405     tmpSh2 = anExp.Current();
1406   }
1407   if(nbf==1) {
1408     TopoDS_Shape sh = aSh2;
1409     while(sh.ShapeType()==TopAbs_COMPOUND) {
1410       TopoDS_Iterator it(sh);
1411       sh = it.Value();
1412     }
1413     Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1414     if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1415         S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1416       if( sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE ) {
1417         // non solid case
1418         double U1,U2,V1,V2;
1419         S->Bounds(U1,U2,V1,V2);
1420         Handle(Geom_RectangularTrimmedSurface) TrS1 = 
1421           new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
1422         Handle(Geom_RectangularTrimmedSurface) TrS2 = 
1423           new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
1424         BRep_Builder B;
1425         TopoDS_Face F1,F2;
1426         TopoDS_Compound Comp;
1427         B.MakeCompound(Comp);
1428         B.MakeFace(F1,TrS1,1.e-7);
1429         B.Add(Comp,F1);
1430         B.MakeFace(F2,TrS2,1.e-7);
1431         B.Add(Comp,F2);
1432         Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
1433         sfs->Init(Comp);
1434         sfs->SetPrecision(1.e-6);
1435         sfs->SetMaxTolerance(1.0);
1436         sfs->Perform();
1437         tmpSh2 = sfs->Shape();
1438         IsChange2 = true;
1439       }
1440       else {
1441         if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
1442           Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
1443           gp_Pnt PC = SS->Location();
1444           BRep_Builder B;
1445           TopoDS_Vertex V;
1446           B.MakeVertex(V,PC,1.e-7);
1447           tmpSh2 = V;
1448           AddDist2 = SS->Radius();
1449           IsChange2 = true;
1450         }
1451         else if( S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1452           Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
1453           gp_Ax3 ax3 = TS->Position();
1454           Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
1455           BRep_Builder B;
1456           TopoDS_Edge E;
1457           B.MakeEdge(E,C,1.e-7);
1458           tmpSh2 = E;
1459           AddDist2 = TS->MinorRadius();
1460           IsChange2 = true;
1461         }
1462       }
1463     }
1464     else
1465       tmpSh2 = aSh2;
1466   }
1467   else
1468     tmpSh2 = aSh2;
1469
1470   if( !IsChange1 && !IsChange2 )
1471     return -2.0;
1472
1473   BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
1474   if (dst.IsDone()) {
1475     double MinDist = 1.e9;
1476     gp_Pnt PMin1, PMin2, P1, P2;
1477     for (int i = 1; i <= dst.NbSolution(); i++) {
1478       P1 = dst.PointOnShape1(i);
1479       P2 = dst.PointOnShape2(i);
1480       Standard_Real Dist = P1.Distance(P2);
1481       if (MinDist > Dist) {
1482         MinDist = Dist;
1483         PMin1 = P1;
1484         PMin2 = P2;
1485       }
1486     }
1487     if(MinDist<1.e-7) {
1488       Ptmp1 = PMin1;
1489       Ptmp2 = PMin2;
1490     }
1491     else {
1492       gp_Dir aDir(gp_Vec(PMin1,PMin2));
1493       if( MinDist > (AddDist1+AddDist2) ) {
1494         Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1495                         PMin1.Y() + aDir.Y()*AddDist1,
1496                         PMin1.Z() + aDir.Z()*AddDist1 );
1497         Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1498                         PMin2.Y() - aDir.Y()*AddDist2,
1499                         PMin2.Z() - aDir.Z()*AddDist2 );
1500         return (MinDist - AddDist1 - AddDist2);
1501       }
1502       else {
1503         if( AddDist1 > 0 ) {
1504           Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
1505                           PMin1.Y() + aDir.Y()*AddDist1,
1506                           PMin1.Z() + aDir.Z()*AddDist1 );
1507           Ptmp2 = Ptmp1;
1508         }
1509         else {
1510           Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
1511                           PMin2.Y() - aDir.Y()*AddDist2,
1512                           PMin2.Z() - aDir.Z()*AddDist2 );
1513           Ptmp1 = Ptmp2;
1514         }
1515       }
1516     }
1517     double res = MinDist - AddDist1 - AddDist2;
1518     if(res<0.) res = 0.0;
1519     return res;
1520   }
1521   return -2.0;
1522 }
1523 /* old variant
1524 static bool CheckSingularCase(const TopoDS_Shape& aSh1,
1525                               const TopoDS_Shape& aSh2,
1526                               gp_Pnt& Ptmp)
1527 {
1528   TopExp_Explorer anExp;
1529   TopoDS_Shape tmpSh1, tmpSh2;
1530   int nbf = 0;
1531   for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1532     nbf++;
1533     tmpSh1 = anExp.Current();
1534   }
1535   if(nbf==1) {
1536     Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1537     if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1538         S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1539       nbf = 0;
1540       for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1541         nbf++;
1542         tmpSh2 = anExp.Current();
1543         Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1544         GeomAPI_IntSS ISS(S1,S2,1.e-7);
1545         if(ISS.IsDone()) {
1546           for(int i=1; i<=ISS.NbLines(); i++) {
1547             Handle(Geom_Curve) C3d = ISS.Line(i);
1548             BRep_Builder B;
1549             TopoDS_Edge E;
1550             B.MakeEdge(E,C3d,1.e-7);
1551             BRepExtrema_DistShapeShape dst(tmpSh2,E);
1552             if (dst.IsDone()) {
1553               gp_Pnt PMin1, PMin2, P1, P2;
1554               double MinDist = 1.e9;
1555               for (int i = 1; i <= dst.NbSolution(); i++) {
1556                 P1 = dst.PointOnShape1(i);
1557                 P2 = dst.PointOnShape2(i);
1558                 Standard_Real Dist = P1.Distance(P2);
1559                 if (MinDist > Dist) {
1560                   MinDist = Dist;
1561                   Ptmp = P1;
1562                 }
1563               }
1564               if(MinDist<1.e-7)
1565                 return true;
1566             }
1567           }
1568         }
1569       }
1570     }
1571   }
1572   nbf = 0;
1573   for ( anExp.Init( aSh2, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1574     nbf++;
1575     tmpSh1 = anExp.Current();
1576   }
1577   if(nbf==1) {
1578     Handle(Geom_Surface) S1 = BRep_Tool::Surface(TopoDS::Face(tmpSh1));
1579     if( S1->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
1580         S1->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
1581       nbf = 0;
1582       for ( anExp.Init( aSh1, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
1583         nbf++;
1584         tmpSh2 = anExp.Current();
1585         Handle(Geom_Surface) S2 = BRep_Tool::Surface(TopoDS::Face(tmpSh2));
1586         GeomAPI_IntSS ISS(S1,S2,1.e-7);
1587         if(ISS.IsDone()) {
1588           for(int i=1; i<=ISS.NbLines(); i++) {
1589             Handle(Geom_Curve) C3d = ISS.Line(i);
1590             BRep_Builder B;
1591             TopoDS_Edge E;
1592             B.MakeEdge(E,C3d,1.e-7);
1593             BRepExtrema_DistShapeShape dst(tmpSh2,E);
1594             if (dst.IsDone()) {
1595               gp_Pnt P1,P2;
1596               double MinDist = 1.e9;
1597               for (int i = 1; i <= dst.NbSolution(); i++) {
1598                 P1 = dst.PointOnShape1(i);
1599                 P2 = dst.PointOnShape2(i);
1600                 Standard_Real Dist = P1.Distance(P2);
1601                 if (MinDist > Dist) {
1602                   MinDist = Dist;
1603                   Ptmp = P1;
1604                 }
1605               }
1606               if(MinDist<1.e-7)
1607                 return true;
1608             }
1609           }
1610         }
1611       }
1612     }
1613   }
1614   return false;
1615 }
1616 */
1617
1618
1619 //=============================================================================
1620 /*!
1621  *  GetMinDistance
1622  */
1623 //=============================================================================
1624 Standard_Real GEOMImpl_IMeasureOperations::GetMinDistance
1625   (Handle(GEOM_Object) theShape1, Handle(GEOM_Object) theShape2,
1626    Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
1627    Standard_Real& X2, Standard_Real& Y2, Standard_Real& Z2)
1628 {
1629   SetErrorCode(KO);
1630   Standard_Real MinDist = 1.e9;
1631
1632   if (theShape1.IsNull() || theShape2.IsNull()) return MinDist;
1633
1634   Handle(GEOM_Function) aRefShape1 = theShape1->GetLastFunction();
1635   Handle(GEOM_Function) aRefShape2 = theShape2->GetLastFunction();
1636   if (aRefShape1.IsNull() || aRefShape2.IsNull()) return MinDist;
1637
1638   TopoDS_Shape aShape1 = aRefShape1->GetValue();
1639   TopoDS_Shape aShape2 = aRefShape2->GetValue();
1640   if (aShape1.IsNull() || aShape2.IsNull()) {
1641     SetErrorCode("One of Objects has NULL Shape");
1642     return MinDist;
1643   }
1644
1645   //Compute the parameters
1646   try {
1647 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1648     OCC_CATCH_SIGNALS;
1649 #endif
1650
1651     // Issue 0020231: A min distance bug with torus and vertex.
1652     // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
1653
1654     // which of shapes consists of only one vertex?
1655     TopExp_Explorer exp1(aShape1,TopAbs_VERTEX), exp2(aShape2,TopAbs_VERTEX);
1656     TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
1657     TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
1658     exp1.Next(); exp2.Next();
1659     if ( exp1.More() ) V1.Nullify();
1660     if ( exp2.More() ) V2.Nullify();
1661     // vertex and container of solids
1662     TopoDS_Shape V = V1.IsNull() ? V2 : V1;
1663     TopoDS_Shape S = V1.IsNull() ? aShape1 : aShape2;
1664     if ( !V.IsNull() ) {
1665       // classify vertex against solids
1666       gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
1667       for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
1668         BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
1669         if ( classifier.State() == TopAbs_IN ) {
1670           p.Coord(X1, Y1, Z1);
1671           p.Coord(X2, Y2, Z2);
1672           SetErrorCode(OK);
1673           return 0.0;
1674         }
1675       }
1676     }
1677     // End Issue 0020231
1678
1679     // skl 30.06.2008
1680     // additional workaround for bugs 19899, 19908 and 19910 from Mantis
1681     gp_Pnt Ptmp1, Ptmp2;
1682     double dist = CheckSingularCase(aShape1, aShape2, Ptmp1, Ptmp2);
1683     if(dist>-1.0) {
1684       Ptmp1.Coord(X1, Y1, Z1);
1685       Ptmp2.Coord(X2, Y2, Z2);
1686       SetErrorCode(OK);
1687       return dist;
1688     }
1689
1690     BRepExtrema_DistShapeShape dst (aShape1, aShape2);
1691     if (dst.IsDone()) {
1692       gp_Pnt PMin1, PMin2, P1, P2;
1693
1694       for (int i = 1; i <= dst.NbSolution(); i++) {
1695         P1 = dst.PointOnShape1(i);
1696         P2 = dst.PointOnShape2(i);
1697
1698         Standard_Real Dist = P1.Distance(P2);
1699         if (MinDist > Dist) {
1700           MinDist = Dist;
1701           PMin1 = P1;
1702           PMin2 = P2;
1703         }
1704       }
1705
1706       PMin1.Coord(X1, Y1, Z1);
1707       PMin2.Coord(X2, Y2, Z2);
1708     }
1709   }
1710   catch (Standard_Failure) {
1711     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1712     SetErrorCode(aFail->GetMessageString());
1713     return MinDist;
1714   }
1715
1716   SetErrorCode(OK);
1717   return MinDist;
1718 }
1719
1720 //=======================================================================
1721 /*!
1722  *  Get coordinates of point
1723  */
1724 //=======================================================================
1725 void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
1726                         Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
1727 {
1728   SetErrorCode(KO);
1729
1730   if (theShape.IsNull())
1731     return;
1732
1733   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1734   if (aRefShape.IsNull())
1735     return;
1736
1737   TopoDS_Shape aShape = aRefShape->GetValue();
1738   if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
1739   {
1740     SetErrorCode( "Shape must be a vertex" );
1741     return;
1742   }
1743
1744   try {
1745 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1746     OCC_CATCH_SIGNALS;
1747 #endif
1748     gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
1749     theX = aPnt.X();
1750     theY = aPnt.Y();
1751     theZ = aPnt.Z();
1752
1753     SetErrorCode(OK);
1754   }
1755   catch (Standard_Failure)
1756   {
1757     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1758     SetErrorCode( aFail->GetMessageString() );
1759   }
1760 }
1761
1762 //=======================================================================
1763 /*!
1764  *  Compute angle (in degrees) between two lines
1765  */
1766 //=======================================================================
1767 Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
1768                                                      Handle(GEOM_Object) theLine2)
1769 {
1770   SetErrorCode(KO);
1771
1772   Standard_Real anAngle = -1.0;
1773
1774   if (theLine1.IsNull() || theLine2.IsNull())
1775     return anAngle;
1776
1777   Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
1778   Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
1779   if (aRefLine1.IsNull() || aRefLine2.IsNull())
1780     return anAngle;
1781
1782   TopoDS_Shape aLine1 = aRefLine1->GetValue();
1783   TopoDS_Shape aLine2 = aRefLine2->GetValue();
1784   if (aLine1.IsNull() || aLine2.IsNull() ||
1785       aLine1.ShapeType() != TopAbs_EDGE ||
1786       aLine2.ShapeType() != TopAbs_EDGE)
1787   {
1788     SetErrorCode("Two edges must be given");
1789     return anAngle;
1790   }
1791
1792   try {
1793 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1794     OCC_CATCH_SIGNALS;
1795 #endif
1796     TopoDS_Edge E1 = TopoDS::Edge(aLine1);
1797     TopoDS_Edge E2 = TopoDS::Edge(aLine2);
1798
1799     double fp,lp;
1800     Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
1801     Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
1802
1803     if ( C1.IsNull() || C2.IsNull() ||
1804         !C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
1805         !C2->IsKind(STANDARD_TYPE(Geom_Line)))
1806     {
1807       SetErrorCode("The edges must be linear");
1808       return anAngle;
1809     }
1810
1811     Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
1812     Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
1813
1814     gp_Lin aLin1 = L1->Lin();
1815     gp_Lin aLin2 = L2->Lin();
1816
1817     anAngle = aLin1.Angle(aLin2);
1818     anAngle /= PI180; // convert radians into degrees
1819
1820     SetErrorCode(OK);
1821   }
1822   catch (Standard_Failure)
1823   {
1824     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1825     SetErrorCode(aFail->GetMessageString());
1826   }
1827
1828   return anAngle;
1829 }
1830
1831
1832 //=============================================================================
1833 /*!
1834  *  CurveCurvatureByParam
1835  */
1836 //=============================================================================
1837 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByParam
1838                         (Handle(GEOM_Object) theCurve, Standard_Real& theParam)
1839 {
1840   SetErrorCode(KO);
1841   Standard_Real aRes = -1.0;
1842
1843   if(theCurve.IsNull()) return aRes;
1844
1845   Handle(GEOM_Function) aRefShape = theCurve->GetLastFunction();
1846   if(aRefShape.IsNull()) return aRes;
1847
1848   TopoDS_Shape aShape = aRefShape->GetValue();
1849   if(aShape.IsNull()) {
1850     SetErrorCode("One of Objects has NULL Shape");
1851     return aRes;
1852   }
1853
1854   Standard_Real aFP, aLP, aP;
1855   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
1856   aP = aFP + (aLP - aFP) * theParam;
1857
1858   if(aCurve.IsNull()) return aRes;
1859
1860   //Compute curvature
1861   try {
1862 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1863     OCC_CATCH_SIGNALS;
1864 #endif
1865     GeomLProp_CLProps Prop = GeomLProp_CLProps 
1866       (aCurve, aP, 2, Precision::Confusion());
1867     aRes = fabs(Prop.Curvature());
1868     SetErrorCode(OK);
1869   }
1870   catch (Standard_Failure) {
1871     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1872     SetErrorCode(aFail->GetMessageString());
1873     return aRes;
1874   }
1875
1876   if( aRes > Precision::Confusion() )
1877     aRes = 1/aRes;
1878   else
1879     aRes = RealLast();
1880   
1881   return aRes;
1882 }
1883
1884
1885 //=============================================================================
1886 /*!
1887  *  CurveCurvatureByPoint
1888  */
1889 //=============================================================================
1890 Standard_Real GEOMImpl_IMeasureOperations::CurveCurvatureByPoint
1891                    (Handle(GEOM_Object) theCurve, Handle(GEOM_Object) thePoint)
1892 {
1893   SetErrorCode(KO);
1894   Standard_Real aRes = -1.0;
1895
1896   if( theCurve.IsNull() || thePoint.IsNull() ) return aRes;
1897
1898   Handle(GEOM_Function) aRefCurve = theCurve->GetLastFunction();
1899   Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
1900   if( aRefCurve.IsNull() || aRefPoint.IsNull() ) return aRes;
1901
1902   TopoDS_Edge anEdge = TopoDS::Edge(aRefCurve->GetValue());
1903   TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
1904   if( anEdge.IsNull() || aPnt.IsNull() ) {
1905     SetErrorCode("One of Objects has NULL Shape");
1906     return aRes;
1907   }
1908
1909   Standard_Real aFP, aLP;
1910   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFP, aLP);
1911   if(aCurve.IsNull()) return aRes;
1912   gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
1913
1914   //Compute curvature
1915   try {
1916 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1917     OCC_CATCH_SIGNALS;
1918 #endif
1919     GeomAPI_ProjectPointOnCurve PPC(aPoint, aCurve, aFP, aLP);
1920     if(PPC.NbPoints()>0) {
1921       GeomLProp_CLProps Prop = GeomLProp_CLProps 
1922         (aCurve, PPC.LowerDistanceParameter(), 2, Precision::Confusion());
1923       aRes = fabs(Prop.Curvature());
1924       SetErrorCode(OK);
1925     }
1926   }
1927   catch (Standard_Failure) {
1928     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1929     SetErrorCode(aFail->GetMessageString());
1930     return aRes;
1931   }
1932
1933   if( aRes > Precision::Confusion() )
1934     aRes = 1/aRes;
1935   else
1936     aRes = RealLast();
1937   
1938   return aRes;
1939 }
1940
1941
1942 //=============================================================================
1943 /*!
1944  *  getSurfaceCurvatures
1945  */
1946 //=============================================================================
1947 Standard_Real GEOMImpl_IMeasureOperations::getSurfaceCurvatures
1948                                           (const Handle(Geom_Surface)& aSurf,
1949                                            Standard_Real theUParam,
1950                                            Standard_Real theVParam,
1951                                            Standard_Boolean theNeedMaxCurv)
1952 {
1953   SetErrorCode(KO);
1954   Standard_Real aRes = 1.0;
1955
1956   if (aSurf.IsNull()) return aRes;
1957
1958   try {
1959 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1960     OCC_CATCH_SIGNALS;
1961 #endif
1962     GeomLProp_SLProps Prop = GeomLProp_SLProps 
1963       (aSurf, theUParam, theVParam, 2, Precision::Confusion());
1964     if(Prop.IsCurvatureDefined()) {
1965       if(Prop.IsUmbilic()) {
1966         //cout<<"is umbilic"<<endl;
1967         aRes = fabs(Prop.MeanCurvature());
1968       }
1969       else {
1970         //cout<<"is not umbilic"<<endl;
1971         double c1 = fabs(Prop.MaxCurvature());
1972         double c2 = fabs(Prop.MinCurvature());
1973         if(theNeedMaxCurv)
1974           aRes = Max(c1,c2);
1975         else
1976           aRes = Min(c1,c2);
1977       }
1978       SetErrorCode(OK);
1979     }
1980   }
1981   catch (Standard_Failure) {
1982     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1983     SetErrorCode(aFail->GetMessageString());
1984     return aRes;
1985   }
1986
1987   if( fabs(aRes) > Precision::Confusion() )
1988     aRes = 1/aRes;
1989   else
1990     aRes = RealLast();
1991   
1992   return aRes;
1993 }
1994
1995
1996 //=============================================================================
1997 /*!
1998  *  MaxSurfaceCurvatureByParam
1999  */
2000 //=============================================================================
2001 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByParam
2002                                                   (Handle(GEOM_Object) theSurf,
2003                                                    Standard_Real& theUParam,
2004                                                    Standard_Real& theVParam)
2005 {
2006   SetErrorCode(KO);
2007   Standard_Real aRes = -1.0;
2008
2009   if (theSurf.IsNull()) return aRes;
2010
2011   Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2012   if(aRefShape.IsNull()) return aRes;
2013
2014   TopoDS_Shape aShape = aRefShape->GetValue();
2015   if(aShape.IsNull()) {
2016     SetErrorCode("One of Objects has NULL Shape");
2017     return aRes;
2018   }
2019
2020   TopoDS_Face F = TopoDS::Face(aShape);
2021   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2022
2023   //Compute the parameters
2024   Standard_Real U1,U2,V1,V2;
2025   ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2026   Standard_Real U = U1 + (U2-U1)*theUParam;
2027   Standard_Real V = V1 + (V2-V1)*theVParam;
2028   
2029   return getSurfaceCurvatures(aSurf, U, V, true);
2030 }
2031
2032
2033 //=============================================================================
2034 /*!
2035  *  MaxSurfaceCurvatureByPoint
2036  */
2037 //=============================================================================
2038 Standard_Real GEOMImpl_IMeasureOperations::MaxSurfaceCurvatureByPoint
2039                     (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2040 {
2041   SetErrorCode(KO);
2042   Standard_Real aRes = -1.0;
2043
2044   if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2045
2046   Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2047   Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2048   if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2049
2050   TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2051   TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2052   if( aFace.IsNull() || aPnt.IsNull() ) {
2053     SetErrorCode("One of Objects has NULL Shape");
2054     return 0;
2055   }
2056
2057   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2058   if(aSurf.IsNull()) return aRes;
2059   gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2060
2061   //Compute the parameters
2062   ShapeAnalysis_Surface sas(aSurf);
2063   gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2064
2065   return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), true);
2066 }
2067
2068
2069 //=============================================================================
2070 /*!
2071  *  MinSurfaceCurvatureByParam
2072  */
2073 //=============================================================================
2074 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByParam
2075                                                   (Handle(GEOM_Object) theSurf,
2076                                                    Standard_Real& theUParam,
2077                                                    Standard_Real& theVParam)
2078 {
2079   SetErrorCode(KO);
2080   Standard_Real aRes = -1.0;
2081
2082   if (theSurf.IsNull()) return aRes;
2083
2084   Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2085   if(aRefShape.IsNull()) return aRes;
2086
2087   TopoDS_Shape aShape = aRefShape->GetValue();
2088   if(aShape.IsNull()) {
2089     SetErrorCode("One of Objects has NULL Shape");
2090     return aRes;
2091   }
2092
2093   TopoDS_Face F = TopoDS::Face(aShape);
2094   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
2095
2096   //Compute the parameters
2097   Standard_Real U1,U2,V1,V2;
2098   ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
2099   Standard_Real U = U1 + (U2-U1)*theUParam;
2100   Standard_Real V = V1 + (V2-V1)*theVParam;
2101   
2102   return getSurfaceCurvatures(aSurf, U, V, false);
2103 }
2104
2105
2106 //=============================================================================
2107 /*!
2108  *  MinSurfaceCurvatureByPoint
2109  */
2110 //=============================================================================
2111 Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint
2112                     (Handle(GEOM_Object) theSurf, Handle(GEOM_Object) thePoint)
2113 {
2114   SetErrorCode(KO);
2115   Standard_Real aRes = -1.0;
2116
2117   if( theSurf.IsNull() || thePoint.IsNull() ) return aRes;
2118
2119   Handle(GEOM_Function) aRefShape = theSurf->GetLastFunction();
2120   Handle(GEOM_Function) aRefPoint = thePoint->GetLastFunction();
2121   if( aRefShape.IsNull() || aRefPoint.IsNull() ) return aRes;
2122
2123   TopoDS_Face aFace = TopoDS::Face(aRefShape->GetValue());
2124   TopoDS_Vertex aPnt = TopoDS::Vertex(aRefPoint->GetValue());
2125   if( aFace.IsNull() || aPnt.IsNull() ) {
2126     SetErrorCode("One of Objects has NULL Shape");
2127     return 0;
2128   }
2129
2130   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
2131   if(aSurf.IsNull()) return aRes;
2132   gp_Pnt aPoint = BRep_Tool::Pnt(aPnt);
2133
2134   //Compute the parameters
2135   ShapeAnalysis_Surface sas(aSurf);
2136   gp_Pnt2d UV = sas.ValueOfUV(aPoint,Precision::Confusion());
2137
2138   return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false);
2139 }
2140
2141
2142 //=======================================================================
2143 //function : StructuralDump
2144 //purpose  : Structural (data exchange) style of output.
2145 //=======================================================================
2146 void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna,
2147                                                   const TopoDS_Shape&       theShape,
2148                                                   TCollection_AsciiString&  theDump)
2149 {
2150   Standard_Integer i;
2151   theDump.Clear();
2152   theDump += " -- The Shape has problems :\n";
2153   theDump += "  Check                                    Count\n";
2154   theDump += " ------------------------------------------------\n";
2155
2156   Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail;
2157   Handle(TColStd_HArray1OfInteger) NbProblems =
2158     new TColStd_HArray1OfInteger(1, last_stat);
2159   for (i = 1; i <= last_stat; i++)
2160     NbProblems->SetValue(i,0);
2161
2162   Handle(TopTools_HSequenceOfShape) sl;
2163   sl = new TopTools_HSequenceOfShape();
2164   TopTools_DataMapOfShapeListOfShape theMap;
2165   theMap.Clear();
2166   GetProblemShapes(theAna, theShape, sl, NbProblems, theMap);
2167   theMap.Clear();
2168
2169   Standard_Integer count = 0;
2170   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve);
2171   if (count > 0) {
2172     theDump += "  Invalid Point on Curve ................... ";
2173     theDump += TCollection_AsciiString(count) + "\n";
2174   }
2175   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface);
2176   if (count > 0) {
2177     theDump += "  Invalid Point on CurveOnSurface .......... ";
2178     theDump += TCollection_AsciiString(count) + "\n";
2179   }
2180   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface);
2181   if (count > 0) {
2182     theDump += "  Invalid Point on Surface ................. ";
2183     theDump += TCollection_AsciiString(count) + "\n";
2184   }
2185   count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve);
2186   if (count > 0) {
2187     theDump += "  No 3D Curve .............................. ";
2188     theDump += TCollection_AsciiString(count) + "\n";
2189   }
2190   count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve);
2191   if (count > 0) {
2192     theDump += "  Multiple 3D Curve ........................ ";
2193     theDump += TCollection_AsciiString(count) + "\n";
2194   }
2195   count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve);
2196   if (count > 0) {
2197     theDump += "  Invalid 3D Curve ......................... ";
2198     theDump += TCollection_AsciiString(count) + "\n";
2199   }
2200   count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface);
2201   if (count > 0) {
2202     theDump += "  No Curve on Surface ...................... ";
2203     theDump += TCollection_AsciiString(count) + "\n";
2204   }
2205   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface);
2206   if (count > 0) {
2207     theDump += "  Invalid Curve on Surface ................. ";
2208     theDump += TCollection_AsciiString(count) + "\n";
2209   }
2210   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface);
2211   if (count > 0) {
2212     theDump += "  Invalid Curve on closed Surface .......... ";
2213     theDump += TCollection_AsciiString(count) + "\n";
2214   }
2215   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag);
2216   if (count > 0) {
2217     theDump += "  Invalid SameRange Flag ................... ";
2218     theDump += TCollection_AsciiString(count) + "\n";
2219   }
2220   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag);
2221   if (count > 0) {
2222     theDump += "  Invalid SameParameter Flag ............... ";
2223     theDump += TCollection_AsciiString(count) + "\n";
2224   }
2225   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag);
2226   if (count > 0) {
2227     theDump += "  Invalid Degenerated Flag ................. ";
2228     theDump += TCollection_AsciiString(count) + "\n";
2229   }
2230   count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge);
2231   if (count > 0) {
2232     theDump += "  Free Edge ................................ ";
2233     theDump += TCollection_AsciiString(count) + "\n";
2234   }
2235   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity);
2236   if (count > 0) {
2237     theDump += "  Invalid MultiConnexity ................... ";
2238     theDump += TCollection_AsciiString(count) + "\n";
2239   }
2240   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange);
2241   if (count > 0) {
2242     theDump += "  Invalid Range ............................ ";
2243     theDump += TCollection_AsciiString(count) + "\n";
2244   }
2245   count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire);
2246   if (count > 0) {
2247     theDump += "  Empty Wire ............................... ";
2248     theDump += TCollection_AsciiString(count) + "\n";
2249   }
2250   count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge);
2251   if (count > 0) {
2252     theDump += "  Redundant Edge ........................... ";
2253     theDump += TCollection_AsciiString(count) + "\n";
2254   }
2255   count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire);
2256   if (count > 0) {
2257     theDump += "  Self Intersecting Wire ................... ";
2258     theDump += TCollection_AsciiString(count) + "\n";
2259   }
2260   count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface);
2261   if (count > 0) {
2262     theDump += "  No Surface ............................... ";
2263     theDump += TCollection_AsciiString(count) + "\n";
2264   }
2265   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire);
2266   if (count > 0) {
2267     theDump += "  Invalid Wire ............................. ";
2268     theDump += TCollection_AsciiString(count) + "\n";
2269   }
2270   count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire);
2271   if (count > 0) {
2272     theDump += "  Redundant Wire ........................... ";
2273     theDump += TCollection_AsciiString(count) + "\n";
2274   }
2275   count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires);
2276   if (count > 0) {
2277     theDump += "  Intersecting Wires ....................... ";
2278     theDump += TCollection_AsciiString(count) + "\n";
2279   }
2280   count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires);
2281   if (count > 0) {
2282     theDump += "  Invalid Imbrication of Wires ............. ";
2283     theDump += TCollection_AsciiString(count) + "\n";
2284   }
2285   count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell);
2286   if (count > 0) {
2287     theDump += "  Empty Shell .............................. ";
2288     theDump += TCollection_AsciiString(count) + "\n";
2289   }
2290   count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace);
2291   if (count > 0) {
2292     theDump += "  Redundant Face ........................... ";
2293     theDump += TCollection_AsciiString(count) + "\n";
2294   }
2295   count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape);
2296   if (count > 0) {
2297     theDump += "  Unorientable Shape ....................... ";
2298     theDump += TCollection_AsciiString(count) + "\n";
2299   }
2300   count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed);
2301   if (count > 0) {
2302     theDump += "  Not Closed ............................... ";
2303     theDump += TCollection_AsciiString(count) + "\n";
2304   }
2305   count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected);
2306   if (count > 0) {
2307     theDump += "  Not Connected ............................ ";
2308     theDump += TCollection_AsciiString(count) + "\n";
2309   }
2310   count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape);
2311   if (count > 0) {
2312     theDump += "  Subshape not in Shape .................... ";
2313     theDump += TCollection_AsciiString(count) + "\n";
2314   }
2315   count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation);
2316   if (count > 0) {
2317     theDump += "  Bad Orientation .......................... ";
2318     theDump += TCollection_AsciiString(count) + "\n";
2319   }
2320   count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape);
2321   if (count > 0) {
2322     theDump += "  Bad Orientation of Subshape .............. ";
2323     theDump += TCollection_AsciiString(count) + "\n";
2324   }
2325   count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail);
2326   if (count > 0) {
2327     theDump += "  checkshape failure ....................... ";
2328     theDump += TCollection_AsciiString(count) + "\n";
2329   }
2330
2331   theDump += " ------------------------------------------------\n";
2332   theDump += "*** Shapes with problems : ";
2333   theDump += TCollection_AsciiString(sl->Length()) + "\n";
2334
2335   Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo;
2336   nbv = nbe = nbw = nbf = nbs = nbo = 0;
2337
2338   for (i = 1; i <= sl->Length(); i++) {
2339     TopoDS_Shape shi = sl->Value(i);
2340     TopAbs_ShapeEnum sti = shi.ShapeType();
2341     switch (sti) {
2342       case TopAbs_VERTEX : nbv++; break;
2343       case TopAbs_EDGE   : nbe++; break;
2344       case TopAbs_WIRE   : nbw++; break;
2345       case TopAbs_FACE   : nbf++; break;
2346       case TopAbs_SHELL  : nbs++; break;
2347       case TopAbs_SOLID  : nbo++; break;
2348       default            : break;
2349     }
2350   }
2351
2352   if (nbv > 0) {
2353     theDump += "VERTEX : ";
2354     if (nbv < 10) theDump += " ";
2355     theDump += TCollection_AsciiString(nbv) + "\n";
2356   }
2357   if (nbe > 0) {
2358     theDump += "EDGE   : ";
2359     if (nbe < 10) theDump += " ";
2360     theDump += TCollection_AsciiString(nbe) + "\n";
2361   }
2362   if (nbw > 0) {
2363     theDump += "WIRE   : ";
2364     if (nbw < 10) theDump += " ";
2365     theDump += TCollection_AsciiString(nbw) + "\n";
2366   }
2367   if (nbf > 0) {
2368     theDump += "FACE   : ";
2369     if (nbf < 10) theDump += " ";
2370     theDump += TCollection_AsciiString(nbf) + "\n";
2371   }
2372   if (nbs > 0) {
2373     theDump += "SHELL  : ";
2374     if (nbs < 10) theDump += " ";
2375     theDump += TCollection_AsciiString(nbs) + "\n";
2376   }
2377   if (nbo > 0) {
2378     theDump += "SOLID  : ";
2379     if (nbo < 10) theDump += " ";
2380     theDump += TCollection_AsciiString(nbo) + "\n";
2381   }
2382 }
2383
2384
2385 //=======================================================================
2386 //function : GetProblemShapes
2387 // purpose : for StructuralDump
2388 //=======================================================================
2389 void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer&           theAna,
2390                                                     const TopoDS_Shape&                 theShape,
2391                                                     Handle(TopTools_HSequenceOfShape)&  sl,
2392                                                     Handle(TColStd_HArray1OfInteger)&   NbProblems,
2393                                                     TopTools_DataMapOfShapeListOfShape& theMap)
2394 {
2395   for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) {
2396     GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap);
2397   }
2398   TopAbs_ShapeEnum styp = theShape.ShapeType();
2399   BRepCheck_ListIteratorOfListOfStatus itl;
2400   TopTools_ListOfShape empty;
2401   if (!theMap.IsBound(theShape)) {
2402     theMap.Bind(theShape,empty);
2403
2404     if (!theAna.Result(theShape).IsNull()) {
2405       itl.Initialize(theAna.Result(theShape)->Status());
2406       // !!! May be, we have to print all the problems, not only the first one ?
2407       if (itl.Value() != BRepCheck_NoError) {
2408         sl->Append(theShape);
2409         BRepCheck_Status stat = itl.Value();
2410         NbProblems->SetValue((Standard_Integer)stat,
2411                              NbProblems->Value((Standard_Integer)stat) + 1);
2412       }
2413     }
2414   }
2415
2416   switch (styp) {
2417   case TopAbs_EDGE:
2418     GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2419     break;
2420   case TopAbs_FACE:
2421     GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap);
2422     GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap);
2423     GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap);
2424     break;
2425   case TopAbs_SHELL:
2426     break;
2427   case TopAbs_SOLID:
2428     GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap);
2429     break;
2430   default:
2431     break;
2432   }
2433 }
2434
2435 //=======================================================================
2436 //function : Contains
2437 //=======================================================================
2438 static Standard_Boolean Contains (const TopTools_ListOfShape& L,
2439                                   const TopoDS_Shape& S)
2440 {
2441   TopTools_ListIteratorOfListOfShape it;
2442   for (it.Initialize(L); it.More(); it.Next()) {
2443     if (it.Value().IsSame(S)) {
2444       return Standard_True;
2445     }
2446   }
2447   return Standard_False;
2448 }
2449
2450 //=======================================================================
2451 //function : GetProblemSub
2452 // purpose : for StructuralDump
2453 //=======================================================================
2454 void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer&           theAna,
2455                                                  const TopoDS_Shape&                 theShape,
2456                                                  Handle(TopTools_HSequenceOfShape)&  sl,
2457                                                  Handle(TColStd_HArray1OfInteger)&   NbProblems,
2458                                                  const TopAbs_ShapeEnum              Subtype,
2459                                                  TopTools_DataMapOfShapeListOfShape& theMap)
2460 {
2461   BRepCheck_ListIteratorOfListOfStatus itl;
2462   TopExp_Explorer exp;
2463   for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) {
2464     const TopoDS_Shape& sub = exp.Current();
2465
2466     const Handle(BRepCheck_Result)& res = theAna.Result(sub);
2467     for (res->InitContextIterator();
2468          res->MoreShapeInContext();
2469          res->NextShapeInContext()) {
2470       if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) {
2471         theMap(sub).Append(theShape);
2472         itl.Initialize(res->StatusOnShape());
2473
2474         if (itl.Value() != BRepCheck_NoError) {
2475           Standard_Integer ii = 0;
2476
2477           for (ii = 1; ii <= sl->Length(); ii++)
2478             if (sl->Value(ii).IsSame(sub)) break;
2479
2480           if (ii > sl->Length()) {
2481             sl->Append(sub);
2482             BRepCheck_Status stat = itl.Value();
2483             NbProblems->SetValue((Standard_Integer)stat,
2484                                  NbProblems->Value((Standard_Integer)stat) + 1);
2485           }
2486           for (ii = 1; ii <= sl->Length(); ii++)
2487             if (sl->Value(ii).IsSame(theShape)) break;
2488           if (ii > sl->Length()) {
2489             sl->Append(theShape);
2490             BRepCheck_Status stat = itl.Value();
2491             NbProblems->SetValue((Standard_Integer)stat,
2492                                  NbProblems->Value((Standard_Integer)stat) + 1);
2493           }
2494         }
2495         break;
2496       }
2497     }
2498   }
2499 }