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