Salome HOME
Implemented [bos #35094] [EDF] (2023-T1) X,Y,Z to U,V.
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 #include <Standard_Stream.hxx>
24 #include <TColStd_HArray1OfReal.hxx>
25
26 #include "GEOM_IMeasureOperations_i.hh"
27
28 #include "utilities.h"
29 #include "OpUtil.hxx"
30
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
33
34 /**
35  * This function converts shape errors from theErrorsFrom to theErrorsTo.
36  * Note that theErrorsTo is not cleared at first.
37  *
38  * \param theErrorsFrom errors to be converted.
39  * \param theErrorsTo result errors.
40  */
41 static void ConvertShapeError
42     (const GEOM::GEOM_IMeasureOperations::ShapeErrors         &theErrorsFrom,
43            std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsTo)
44 {
45   int aNbErr = theErrorsFrom.length();
46   int i = 0;
47
48   for (; i < aNbErr; i++) {
49     const GEOM::GEOM_IMeasureOperations::ShapeError anErr = theErrorsFrom[i];
50     const GEOM::GEOM_IMeasureOperations::ShapeErrorType aType = anErr.error;
51     const GEOM::ListOfLong anIncrims = anErr.incriminated;
52     GEOMImpl_IMeasureOperations::ShapeError anErrStruct;
53
54     switch (aType) {
55     case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve:
56       anErrStruct.error = BRepCheck_InvalidPointOnCurve;
57       break;
58     case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface:
59       anErrStruct.error = BRepCheck_InvalidPointOnCurveOnSurface;
60       break;
61     case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface:
62       anErrStruct.error = BRepCheck_InvalidPointOnSurface;
63       break;
64     case GEOM::GEOM_IMeasureOperations::No3DCurve:
65       anErrStruct.error = BRepCheck_No3DCurve;
66       break;
67     case GEOM::GEOM_IMeasureOperations::Multiple3DCurve:
68       anErrStruct.error = BRepCheck_Multiple3DCurve;
69       break;
70     case GEOM::GEOM_IMeasureOperations::Invalid3DCurve:
71       anErrStruct.error = BRepCheck_Invalid3DCurve;
72       break;
73     case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface:
74       anErrStruct.error = BRepCheck_NoCurveOnSurface;
75       break;
76     case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface:
77       anErrStruct.error = BRepCheck_InvalidCurveOnSurface;
78       break;
79     case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface:
80       anErrStruct.error = BRepCheck_InvalidCurveOnClosedSurface;
81       break;
82     case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag:
83       anErrStruct.error = BRepCheck_InvalidSameRangeFlag;
84       break;
85     case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag:
86       anErrStruct.error = BRepCheck_InvalidSameParameterFlag;
87       break;
88     case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag:
89       anErrStruct.error = BRepCheck_InvalidDegeneratedFlag;
90       break;
91     case GEOM::GEOM_IMeasureOperations::FreeEdge:
92       anErrStruct.error = BRepCheck_FreeEdge;
93       break;
94     case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity:
95       anErrStruct.error = BRepCheck_InvalidMultiConnexity;
96       break;
97     case GEOM::GEOM_IMeasureOperations::InvalidRange:
98       anErrStruct.error = BRepCheck_InvalidRange;
99       break;
100     case GEOM::GEOM_IMeasureOperations::EmptyWire:
101       anErrStruct.error = BRepCheck_EmptyWire;
102       break;
103     case GEOM::GEOM_IMeasureOperations::RedundantEdge:
104       anErrStruct.error = BRepCheck_RedundantEdge;
105       break;
106     case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire:
107       anErrStruct.error = BRepCheck_SelfIntersectingWire;
108       break;
109     case GEOM::GEOM_IMeasureOperations::NoSurface:
110       anErrStruct.error = BRepCheck_NoSurface;
111       break;
112     case GEOM::GEOM_IMeasureOperations::InvalidWire:
113       anErrStruct.error = BRepCheck_InvalidWire;
114       break;
115     case GEOM::GEOM_IMeasureOperations::RedundantWire:
116       anErrStruct.error = BRepCheck_RedundantWire;
117       break;
118     case GEOM::GEOM_IMeasureOperations::IntersectingWires:
119       anErrStruct.error = BRepCheck_IntersectingWires;
120       break;
121     case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires:
122       anErrStruct.error = BRepCheck_InvalidImbricationOfWires;
123       break;
124     case GEOM::GEOM_IMeasureOperations::EmptyShell:
125       anErrStruct.error = BRepCheck_EmptyShell;
126       break;
127     case GEOM::GEOM_IMeasureOperations::RedundantFace:
128       anErrStruct.error = BRepCheck_RedundantFace;
129       break;
130     case GEOM::GEOM_IMeasureOperations::UnorientableShape:
131       anErrStruct.error = BRepCheck_UnorientableShape;
132       break;
133     case GEOM::GEOM_IMeasureOperations::NotClosed:
134       anErrStruct.error = BRepCheck_NotClosed;
135       break;
136     case GEOM::GEOM_IMeasureOperations::NotConnected:
137       anErrStruct.error = BRepCheck_NotConnected;
138       break;
139     case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape:
140       anErrStruct.error = BRepCheck_SubshapeNotInShape;
141       break;
142     case GEOM::GEOM_IMeasureOperations::BadOrientation:
143       anErrStruct.error = BRepCheck_BadOrientation;
144       break;
145     case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape:
146       anErrStruct.error = BRepCheck_BadOrientationOfSubshape;
147       break;
148     case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue:
149       anErrStruct.error = BRepCheck_InvalidToleranceValue;
150       break;
151     case GEOM::GEOM_IMeasureOperations::CheckFail:
152       anErrStruct.error = BRepCheck_CheckFail;
153       break;
154     default:
155       break;
156     }
157
158     int ii = 0;
159     int aLen = anIncrims.length();
160
161     for (; ii < aLen; ii++) {
162       anErrStruct.incriminated.push_back(anIncrims[ii]);
163     }
164
165     theErrorsTo.push_back(anErrStruct);
166   }
167 }
168
169 /**
170  * This function converts shape errors from theErrorsFrom to theErrorsTo.
171  * Note that theErrorsTo is not cleared at first.
172  *
173  * \param theErrorsFrom errors to be converted.
174  * \param theErrorsTo result errors.
175  */
176 static void ConvertShapeError
177     (const std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsFrom,
178            GEOM::GEOM_IMeasureOperations::ShapeErrors_out     &theErrorsTo)
179 {
180   const int aNbErr = theErrorsFrom.size();
181   GEOM::GEOM_IMeasureOperations::ShapeErrors_var anErrArray =
182     new GEOM::GEOM_IMeasureOperations::ShapeErrors;
183
184   anErrArray->length(aNbErr);
185
186   // fill the local CORBA array with values from lists
187   std::list<GEOMImpl_IMeasureOperations::ShapeError>::const_iterator
188     anIt = theErrorsFrom.begin();
189   int i = 0;
190
191   for (; anIt != theErrorsFrom.end(); i++, anIt++) {
192     GEOM::GEOM_IMeasureOperations::ShapeError_var anErrStruct =
193       new GEOM::GEOM_IMeasureOperations::ShapeError;
194
195     switch (anIt->error) {
196     case BRepCheck_InvalidPointOnCurve:
197       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve;
198       break;
199     case BRepCheck_InvalidPointOnCurveOnSurface:
200       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface;
201       break;
202     case BRepCheck_InvalidPointOnSurface:
203       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface;
204       break;
205     case BRepCheck_No3DCurve:
206       anErrStruct->error = GEOM::GEOM_IMeasureOperations::No3DCurve;
207       break;
208     case BRepCheck_Multiple3DCurve:
209       anErrStruct->error = GEOM::GEOM_IMeasureOperations::Multiple3DCurve;
210       break;
211     case BRepCheck_Invalid3DCurve:
212       anErrStruct->error = GEOM::GEOM_IMeasureOperations::Invalid3DCurve;
213       break;
214     case BRepCheck_NoCurveOnSurface:
215       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoCurveOnSurface;
216       break;
217     case BRepCheck_InvalidCurveOnSurface:
218       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface;
219       break;
220     case BRepCheck_InvalidCurveOnClosedSurface:
221       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface;
222       break;
223     case BRepCheck_InvalidSameRangeFlag:
224       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag;
225       break;
226     case BRepCheck_InvalidSameParameterFlag:
227       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag;
228       break;
229     case BRepCheck_InvalidDegeneratedFlag:
230       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag;
231       break;
232     case BRepCheck_FreeEdge:
233       anErrStruct->error = GEOM::GEOM_IMeasureOperations::FreeEdge;
234       break;
235     case BRepCheck_InvalidMultiConnexity:
236       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity;
237       break;
238     case BRepCheck_InvalidRange:
239       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidRange;
240       break;
241     case BRepCheck_EmptyWire:
242       anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyWire;
243       break;
244     case BRepCheck_RedundantEdge:
245       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantEdge;
246       break;
247     case BRepCheck_SelfIntersectingWire:
248       anErrStruct->error = GEOM::GEOM_IMeasureOperations::SelfIntersectingWire;
249       break;
250     case BRepCheck_NoSurface:
251       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoSurface;
252       break;
253     case BRepCheck_InvalidWire:
254       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidWire;
255       break;
256     case BRepCheck_RedundantWire:
257       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantWire;
258       break;
259     case BRepCheck_IntersectingWires:
260       anErrStruct->error = GEOM::GEOM_IMeasureOperations::IntersectingWires;
261       break;
262     case BRepCheck_InvalidImbricationOfWires:
263       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires;
264       break;
265     case BRepCheck_EmptyShell:
266       anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyShell;
267       break;
268     case BRepCheck_RedundantFace:
269       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantFace;
270       break;
271     case BRepCheck_UnorientableShape:
272       anErrStruct->error = GEOM::GEOM_IMeasureOperations::UnorientableShape;
273       break;
274     case BRepCheck_NotClosed:
275       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotClosed;
276       break;
277     case BRepCheck_NotConnected:
278       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotConnected;
279       break;
280     case BRepCheck_SubshapeNotInShape:
281       anErrStruct->error = GEOM::GEOM_IMeasureOperations::SubshapeNotInShape;
282       break;
283     case BRepCheck_BadOrientation:
284       anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientation;
285       break;
286     case BRepCheck_BadOrientationOfSubshape:
287       anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape;
288       break;
289     case BRepCheck_InvalidToleranceValue:
290       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidToleranceValue;
291       break;
292     case BRepCheck_CheckFail:
293       anErrStruct->error = GEOM::GEOM_IMeasureOperations::CheckFail;
294       break;
295     default:
296       break;
297     }
298
299     std::list<int> aIndList = anIt->incriminated;
300     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
301     anIncrims->length(aIndList.size());
302
303     std::list<int>::iterator anIndIt = aIndList.begin();
304     int jj = 0;
305
306     for (; anIndIt != aIndList.end(); jj++, anIndIt++) {
307       anIncrims[jj] = *anIndIt;
308     }
309
310     anErrStruct->incriminated = anIncrims;
311
312     anErrArray[i] = anErrStruct;
313   }
314
315   // initialize out-parameter with local array
316   theErrorsTo = anErrArray._retn();
317 }
318
319 //=============================================================================
320 /*!
321  *   constructor:
322  */
323 //=============================================================================
324 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
325                                                       GEOM::GEOM_Gen_ptr theEngine,
326                                                       ::GEOMImpl_IMeasureOperations* theImpl)
327 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
328 {
329   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
330 }
331
332 //=============================================================================
333 /*!
334  *  destructor
335  */
336 //=============================================================================
337 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
338 {
339   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
340 }
341
342 //=============================================================================
343 /*!
344  *  KindOfShape
345  */
346 //=============================================================================
347 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
348                                    (GEOM::GEOM_Object_ptr  theShape,
349                                     GEOM::ListOfLong_out   theIntegers,
350                                     GEOM::ListOfDouble_out theDoubles)
351 {
352   GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
353
354   // allocate the CORBA arrays
355   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
356   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
357
358   //Get the reference shape
359   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
360
361   if (!aShape.IsNull()) {
362     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
363     Handle(TColStd_HSequenceOfReal)    aDoubles   = new TColStd_HSequenceOfReal;
364
365     // Detect kind of shape and parameters
366     aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
367
368     int nbInts = anIntegers->Length();
369     int nbDbls = aDoubles->Length();
370
371     anIntegersArray->length(nbInts);
372     aDoublesArray->length(nbDbls);
373
374     for (int ii = 0; ii < nbInts; ii++) {
375       anIntegersArray[ii] = anIntegers->Value(ii + 1);
376     }
377     for (int id = 0; id < nbDbls; id++) {
378       aDoublesArray[id] = aDoubles->Value(id + 1);
379     }
380   }
381
382   // initialize out-parameters with local arrays
383   theIntegers = anIntegersArray._retn();
384   theDoubles  = aDoublesArray._retn();
385   return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
386 }
387
388 //=============================================================================
389 /*!
390  *  GetPosition
391  */
392 //=============================================================================
393 void GEOM_IMeasureOperations_i::GetPosition
394                  (GEOM::GEOM_Object_ptr theShape,
395                   CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
396                   CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
397                   CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
398 {
399   //Set a not done flag
400   GetOperations()->SetNotDone();
401
402   //Set default values: global CS
403   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
404   Zz = Xx = 1.;
405
406   //Get the reference shape
407   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
408   if (aShape.IsNull()) return;
409
410   // Get shape parameters
411   GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
412 }
413
414 //=============================================================================
415 /*!
416  *  GetCentreOfMass
417  */
418 //=============================================================================
419 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
420                                               (GEOM::GEOM_Object_ptr theShape)
421 {
422   GEOM::GEOM_Object_var aGEOMObject;
423
424   //Set a not done flag
425   GetOperations()->SetNotDone();
426
427   //Get the reference shape
428   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
429   if (aShape.IsNull()) return aGEOMObject._retn();
430
431   // Make Point - centre of mass of theShape
432   Handle(::GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
433   if (!GetOperations()->IsDone() || anObject.IsNull())
434     return aGEOMObject._retn();
435
436   return GetObject(anObject);
437 }
438
439 //=============================================================================
440 /*!
441  *  GetVertexByIndex
442  */
443 //=============================================================================
444 GEOM::GEOM_Object_ptr
445 GEOM_IMeasureOperations_i::GetVertexByIndex( GEOM::GEOM_Object_ptr theShape,
446                                              CORBA::Long           theIndex,
447                                              CORBA::Boolean        theUseOri )
448 {
449   GEOM::GEOM_Object_var aGEOMObject;
450
451   //Set a not done flag
452   GetOperations()->SetNotDone();
453
454   //Get the reference shape
455   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
456   if ( aShape.IsNull() ) return aGEOMObject._retn();
457
458   // Get vertex by index
459   Handle(::GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex, theUseOri);
460   if (!GetOperations()->IsDone() || anObject.IsNull())
461     return aGEOMObject._retn();
462
463   return GetObject(anObject);
464 }
465
466 //=============================================================================
467 /*!
468  *  GetNormal
469  */
470 //=============================================================================
471 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
472                                        (GEOM::GEOM_Object_ptr theFace,
473                                         GEOM::GEOM_Object_ptr theOptionalPoint)
474 {
475   GEOM::GEOM_Object_var aGEOMObject;
476
477   //Set a not done flag
478   GetOperations()->SetNotDone();
479
480   //Get the reference shape
481   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
482   if (aFace.IsNull()) return aGEOMObject._retn();
483
484   // Get the OptionalPoint (can be not defined)
485   Handle(::GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
486
487   // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
488   Handle(::GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
489   if (!GetOperations()->IsDone() || anObject.IsNull())
490     return aGEOMObject._retn();
491
492   return GetObject(anObject);
493 }
494
495 //=============================================================================
496 /*!
497  *  GetBasicProperties
498  */
499 //=============================================================================
500 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
501                                                     CORBA::Double  theTolerance,
502                                                     CORBA::Double& theLength,
503                                                     CORBA::Double& theSurfArea,
504                                                     CORBA::Double& theVolume)
505 {
506   //Set a not done flag
507   GetOperations()->SetNotDone();
508
509   //Get the reference shape
510   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
511   if (aShape.IsNull()) return;
512
513   // Get shape parameters
514   GetOperations()->GetBasicProperties(aShape, theTolerance, theLength,
515                                       theSurfArea, theVolume);
516 }
517
518 //=============================================================================
519 /*!
520  *  GetInertia
521  */
522 //=============================================================================
523 void GEOM_IMeasureOperations_i::GetInertia
524   (GEOM::GEOM_Object_ptr theShape,
525    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
526    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
527    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
528    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
529 {
530   //Set a not done flag
531   GetOperations()->SetNotDone();
532
533   //Get the reference shape
534   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
535   if (aShape.IsNull()) return;
536
537   // Get shape parameters
538   GetOperations()->GetInertia(aShape,
539                               I11, I12, I13,
540                               I21, I22, I23,
541                               I31, I32, I33,
542                               Ix , Iy , Iz);
543 }
544
545 //=============================================================================
546 /*!
547  *  GetBoundingBox
548  */
549 //=============================================================================
550 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
551                                                 CORBA::Boolean precise,
552                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
553                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
554                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
555 {
556   //Set a not done flag
557   GetOperations()->SetNotDone();
558
559   //Get the reference shape
560   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
561   if (aShape.IsNull()) return;
562
563   // Get shape parameters
564   GetOperations()->GetBoundingBox
565     (aShape, precise, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
566 }
567
568 //=============================================================================
569 /*!
570  *  MakeBoundingBox
571  */
572 //=============================================================================
573 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
574                                               (GEOM::GEOM_Object_ptr theShape,
575                                                CORBA::Boolean precise)
576 {
577   GEOM::GEOM_Object_var aGEOMObject;
578
579   //Set a not done flag
580   GetOperations()->SetNotDone();
581
582   //Get the reference shape
583   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
584   if (aShape.IsNull()) return aGEOMObject._retn();
585
586   // Make Box - bounding box of theShape
587   Handle(::GEOM_Object) anObject =
588     GetOperations()->GetBoundingBox(aShape, precise);
589   if (!GetOperations()->IsDone() || anObject.IsNull())
590     return aGEOMObject._retn();
591
592   return GetObject(anObject);
593 }
594
595 //=============================================================================
596 /*!
597  *  GetTolerance
598  */
599 //=============================================================================
600 void GEOM_IMeasureOperations_i::GetTolerance
601                                 (GEOM::GEOM_Object_ptr theShape,
602                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
603                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
604                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
605 {
606   //Set a not done flag
607   GetOperations()->SetNotDone();
608
609   //Get the reference shape
610   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
611   if (aShape.IsNull()) return;
612
613   // Get shape parameters
614   GetOperations()->GetTolerance(aShape,
615                                 FaceMin, FaceMax,
616                                 EdgeMin, EdgeMax,
617                                 VertMin, VertMax);
618 }
619
620 //=============================================================================
621 /*!
622  *  CheckShape
623  */
624 //=============================================================================
625 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape
626              (GEOM::GEOM_Object_ptr                          theShape,
627               GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
628 {
629   //Set a not done flag
630   GetOperations()->SetNotDone();
631
632   if (CORBA::is_nil(theShape))
633   {
634     return 0;
635   }
636
637   //Get the reference shape
638   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
639
640   if (aShape.IsNull())
641   {
642     return 0;
643   }
644
645   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
646   bool isOk = GetOperations()->CheckShape(aShape, false, anErrList);
647
648   ConvertShapeError(anErrList, theErrors);
649
650   return isOk;
651 }
652
653 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry
654              (GEOM::GEOM_Object_ptr                          theShape,
655               GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
656 {
657   //Set a not done flag
658   GetOperations()->SetNotDone();
659
660   if (CORBA::is_nil(theShape))
661   {
662     return 0;
663   }
664
665   //Get the reference shape
666   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
667
668   if (aShape.IsNull())
669   {
670     return 0;
671   }
672
673   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
674   bool isOk = GetOperations()->CheckShape(aShape, true, anErrList);
675
676   ConvertShapeError(anErrList, theErrors);
677
678   return isOk;
679 }
680
681 //=============================================================================
682 /*!
683  *  PrintShapeErrors
684  */
685 //=============================================================================
686 char* GEOM_IMeasureOperations_i::PrintShapeErrors
687              (      GEOM::GEOM_Object_ptr                       theShape,
688               const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors)
689 {
690   //Get the reference shape
691   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
692
693   if (aShape.IsNull()) {
694     return NULL;
695   }
696
697   // Convert the errors sequence
698   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
699
700   ConvertShapeError(theErrors, anErrList);
701
702   TCollection_AsciiString aDescr =
703     GetOperations()->PrintShapeErrors(aShape, anErrList);
704
705   return CORBA::string_dup(aDescr.ToCString());
706 }
707
708 //=============================================================================
709 /*!
710  *  CheckSelfIntersections
711  */
712 //=============================================================================
713 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
714                                                                   CORBA::Long           theCheckLevel,
715                                                                   GEOM::ListOfLong_out  theIntersections)
716 {
717   // Set a not done flag
718   GetOperations()->SetNotDone();
719
720   bool isGood = false;
721
722   // Allocate the CORBA arrays
723   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
724
725   // Get the reference shape
726   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
727
728   if (!aShape.IsNull()) {
729     GEOMImpl_IMeasureOperations::SICheckLevel aCheckLevel;
730
731     switch(theCheckLevel) {
732     case GEOM::SI_V_V:
733       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_V;
734       break;
735     case GEOM::SI_V_E:
736       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_E;
737       break;
738     case GEOM::SI_E_E:
739       aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_E;
740       break;
741     case GEOM::SI_V_F:
742       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_F;
743       break;
744     case GEOM::SI_E_F:
745       aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_F;
746       break;
747     case GEOM::SI_ALL:
748     default:
749       aCheckLevel = GEOMImpl_IMeasureOperations::SI_ALL;
750       break;
751     }
752
753     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
754
755     // Detect self-intersections
756     isGood = GetOperations()->CheckSelfIntersections
757       (aShape, aCheckLevel, anIntegers);
758
759     int nbInts = anIntegers->Length();
760
761     anIntegersArray->length(nbInts);
762
763     for (int ii = 0; ii < nbInts; ii++) {
764       anIntegersArray[ii] = anIntegers->Value(ii + 1);
765     }
766   }
767
768   // Initialize out-parameters with local arrays
769   theIntersections = anIntegersArray._retn();
770   return isGood;
771 }
772
773 //=============================================================================
774 /*!
775  *  CheckSelfIntersectionsFast
776  */
777 //=============================================================================
778 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersectionsFast 
779   (GEOM::GEOM_Object_ptr theShape,
780    CORBA::Float          theDeflection,
781    CORBA::Double         theTolerance,
782    GEOM::ListOfLong_out  theIntersections)
783 {
784   // Set a not done flag
785   GetOperations()->SetNotDone();
786
787   bool isGood = false;
788
789   // Allocate the CORBA arrays
790   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
791
792   // Get the reference shape
793   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
794
795   if (!aShape.IsNull()) {
796     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
797
798     // Detect self-intersections
799     isGood = GetOperations()->CheckSelfIntersectionsFast
800       (aShape, theDeflection, theTolerance, anIntegers);
801
802     int nbInts = anIntegers->Length();
803
804     anIntegersArray->length(nbInts);
805
806     for (int ii = 0; ii < nbInts; ii++) {
807       anIntegersArray[ii] = anIntegers->Value(ii + 1);
808     }
809   }
810
811   // Initialize out-parameters with local arrays
812   theIntersections = anIntegersArray._retn();
813   return isGood;
814 }
815
816 //=============================================================================
817 /*!
818  *  CheckBOPArguments
819  */
820 //=============================================================================
821 CORBA::Boolean GEOM_IMeasureOperations_i::CheckBOPArguments
822                                       (GEOM::GEOM_Object_ptr theShape)
823 {
824   // Set a not done flag
825   GetOperations()->SetNotDone();
826
827   // Get the reference shape
828   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
829   bool isGood = false;
830
831   if (!aShape.IsNull()) {
832     // Check BOP arguments
833     isGood = GetOperations()->CheckBOPArguments(aShape);
834   }
835
836   return isGood;
837 }
838
839 //=============================================================================
840 /*!
841  *  FastIntersect
842  */
843 //=============================================================================
844 CORBA::Boolean GEOM_IMeasureOperations_i::FastIntersect (GEOM::GEOM_Object_ptr theShape1,
845                                                          GEOM::GEOM_Object_ptr theShape2,
846                                                          CORBA::Double         theTolerance,
847                                                          CORBA::Float          theDeflection,
848                                                          GEOM::ListOfLong_out  theIntersections1,
849                                                          GEOM::ListOfLong_out  theIntersections2)
850 {
851   // Set a not done flag
852   GetOperations()->SetNotDone();
853
854   bool isGood = false;
855
856   // Allocate the CORBA arrays
857   GEOM::ListOfLong_var anIntegersArray1 = new GEOM::ListOfLong();
858   GEOM::ListOfLong_var anIntegersArray2 = new GEOM::ListOfLong();
859
860   // Get the reference shape
861   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
862   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
863   
864   if (!aShape1.IsNull() && !aShape2.IsNull()) {
865     Handle(TColStd_HSequenceOfInteger) anIntegers1 = new TColStd_HSequenceOfInteger;
866     Handle(TColStd_HSequenceOfInteger) anIntegers2 = new TColStd_HSequenceOfInteger;
867
868     // Detect intersections
869     isGood = GetOperations()->FastIntersect
870       (aShape1, aShape2, theTolerance, theDeflection, anIntegers1, anIntegers2);
871
872     int nbInts1 = anIntegers1->Length();
873     int nbInts2 = anIntegers2->Length();
874
875     anIntegersArray1->length(nbInts1);
876     anIntegersArray2->length(nbInts2);
877
878     for (int ii = 0; ii < nbInts1; ii++) {
879       anIntegersArray1[ii] = anIntegers1->Value(ii + 1);
880     }
881     for (int ii = 0; ii < nbInts2; ii++) {
882       anIntegersArray2[ii] = anIntegers2->Value(ii + 1);
883     }
884   }
885
886   // Initialize out-parameters with local arrays
887   theIntersections1 = anIntegersArray1._retn();
888   theIntersections2 = anIntegersArray2._retn();
889   return isGood;
890 }
891
892 //=============================================================================
893 /*!
894  *  IsGoodForSolid
895  */
896 //=============================================================================
897 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
898 {
899   //Set a not done flag
900   GetOperations()->SetNotDone();
901
902   //Get the reference shape
903   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
904   if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
905
906   // Get shape parameters
907   TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
908   return CORBA::string_dup(aDescription.ToCString());
909 }
910
911 //=============================================================================
912 /*!
913  *  WhatIs
914  */
915 //=============================================================================
916 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
917 {
918   //Set a not done flag
919   GetOperations()->SetNotDone();
920
921   //Get the reference shape
922   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
923   if (aShape.IsNull()) return NULL;
924
925   // Get shape parameters
926   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
927   return CORBA::string_dup(aDescription.ToCString());
928 }
929
930 //=============================================================================
931 /*!
932  *  AreCoordsInside
933  */
934 //=============================================================================
935 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
936                                                               const GEOM::ListOfDouble& theCoords,
937                                                               CORBA::Double tolerance)
938 {
939   //Set a not done flag
940   GetOperations()->SetNotDone();
941   
942   int nb_points = theCoords.length()/3;
943
944   GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
945   aResults->length(nb_points);
946   
947   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
948   
949   std::vector<double> tmp(3*nb_points);
950   for (int i = 0; i < 3*nb_points; i++)
951     tmp[i] = theCoords[i];
952   std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
953   for (int i = 0, resSize = res.size();  i < nb_points; i++)
954     aResults[i] = i < resSize ? res[i] : false;
955   return aResults._retn();
956 }
957
958 //=============================================================================
959 /*!
960  *  GetMinDistance
961  */
962 //=============================================================================
963 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
964   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
965    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
966    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
967 {
968   //Set a not done flag
969   GetOperations()->SetNotDone();
970
971   //Get the reference shape
972   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
973   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
974   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
975
976   // Get shape parameters
977   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
978 }
979
980 //=============================================================================
981 /*!
982  *  ClosestPoints
983  */
984 //=============================================================================
985 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
986   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
987    GEOM::ListOfDouble_out theCoords)
988 {
989   //Set a not done flag
990   GetOperations()->SetNotDone();
991
992   // allocate the CORBA array
993   int nbSols = 0;
994   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
995
996   //Get the reference shape
997   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
998   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
999
1000   if (!aShape1.IsNull() && !aShape2.IsNull()) {
1001     Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
1002     // Get shape parameters
1003     nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
1004     int nbDbls = aDoubles->Length();
1005     aDoublesArray->length(nbDbls);
1006     for (int id = 0; id < nbDbls; id++) {
1007       aDoublesArray[id] = aDoubles->Value(id + 1);
1008     }
1009   }
1010
1011   theCoords = aDoublesArray._retn();
1012   return nbSols;
1013 }
1014
1015 //=============================================================================
1016 /*!
1017  *  PointCoordinates
1018  */
1019 //=============================================================================
1020 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
1021                                                   CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
1022
1023 {
1024   //Set a not done flag
1025   GetOperations()->SetNotDone();
1026
1027   //Get the reference shape
1028   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1029   if (aShape.IsNull())
1030     return;
1031
1032   // Get shape parameters
1033   GetOperations()->PointCoordinates( aShape, X, Y, Z );
1034 }
1035
1036 //=============================================================================
1037 /*!
1038  *  GetAngle
1039  */
1040 //=============================================================================
1041 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
1042                                                    GEOM::GEOM_Object_ptr theShape2)
1043 {
1044   //Set a not done flag
1045   GetOperations()->SetNotDone();
1046
1047   //Get the reference shapes
1048   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1049   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1050   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1051
1052   // Get the angle
1053   return GetOperations()->GetAngle(aShape1, aShape2);
1054 }
1055
1056 //=============================================================================
1057 /*!
1058  *  GetAngle
1059  */
1060 //=============================================================================
1061 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
1062                                                              GEOM::GEOM_Object_ptr theShape2)
1063 {
1064   //Set a not done flag
1065   GetOperations()->SetNotDone();
1066
1067   //Get the reference shapes
1068   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1069   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1070   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1071
1072   // Get the angle
1073   return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
1074 }
1075
1076 //=============================================================================
1077 /*!
1078 *  PatchFace
1079 */
1080 //=============================================================================
1081 GEOM::ListOfGO* GEOM_IMeasureOperations_i::PatchFace(GEOM::GEOM_Object_ptr theShape)
1082 {
1083   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1084
1085   //Get the reference shape
1086   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1087   if (aShapeRef.IsNull()) return aSeq._retn();
1088
1089   // Perform patch face operation
1090   Handle(TColStd_HSequenceOfTransient) aHSeq =
1091     GetOperations()->PatchFace(aShapeRef);
1092   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1093     return aSeq._retn();
1094
1095   Standard_Integer aLength = aHSeq->Length();
1096   aSeq->length(aLength);
1097   for (Standard_Integer i = 1; i <= aLength; i++)
1098     aSeq[i - 1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1099
1100   return aSeq._retn();
1101 }
1102
1103 //=============================================================================
1104 /*!
1105  *  CurveCurvatureByParam
1106  */
1107 //=============================================================================
1108 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
1109                        (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
1110 {
1111   //Set a not done flag
1112   GetOperations()->SetNotDone();
1113
1114   //Get the reference shape
1115   Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1116   if(aShape.IsNull()) return -1.0;
1117
1118   return GetOperations()->CurveCurvatureByParam(aShape,theParam);
1119 }
1120
1121 //=============================================================================
1122 /*!
1123  *  CurveCurvatureByPoint
1124  */
1125 //=============================================================================
1126 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
1127                (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
1128 {
1129   //Set a not done flag
1130   GetOperations()->SetNotDone();
1131
1132   //Get the reference shape
1133   Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1134   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1135   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1136
1137   return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
1138 }
1139
1140
1141 //=============================================================================
1142 /*!
1143  *  MaxSurfaceCurvatureByParam
1144  */
1145 //=============================================================================
1146 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
1147                                                 (GEOM::GEOM_Object_ptr theSurf,
1148                                                  CORBA::Double theUParam,
1149                                                  CORBA::Double theVParam)
1150 {
1151   //Set a not done flag
1152   GetOperations()->SetNotDone();
1153
1154   //Get the reference shape
1155   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1156   if(aShape.IsNull()) return -1.0;
1157
1158   return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1159 }
1160
1161 //=============================================================================
1162 /*!
1163  *  MaxSurfaceCurvatureByPoint
1164  */
1165 //=============================================================================
1166 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
1167                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1168 {
1169   //Set a not done flag
1170   GetOperations()->SetNotDone();
1171
1172   //Get the reference shape
1173   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1174   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1175   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1176
1177   return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
1178 }
1179
1180 //=============================================================================
1181 /*!
1182  *  MinSurfaceCurvatureByParam
1183  */
1184 //=============================================================================
1185 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
1186                                                 (GEOM::GEOM_Object_ptr theSurf,
1187                                                  CORBA::Double theUParam,
1188                                                  CORBA::Double theVParam)
1189 {
1190   //Set a not done flag
1191   GetOperations()->SetNotDone();
1192
1193   //Get the reference shape
1194   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1195   if (aShape.IsNull()) return -1.0;
1196
1197   return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1198 }
1199
1200 //=============================================================================
1201 /*!
1202  *  MinSurfaceCurvatureByPoint
1203  */
1204 //=============================================================================
1205 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
1206                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1207 {
1208   //Set a not done flag
1209   GetOperations()->SetNotDone();
1210
1211   //Get the reference shape
1212   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1213   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1214   if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
1215
1216   return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);
1217 }
1218
1219 //=============================================================================
1220 /*!
1221  *  SurfaceCurvatureByPointAndDirection
1222  */
1223 //=============================================================================
1224 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::SurfaceCurvatureByPointAndDirection
1225                                           (GEOM::GEOM_Object_ptr theSurf,
1226                                            GEOM::GEOM_Object_ptr thePoint,
1227                                            GEOM::GEOM_Object_ptr theDirection)
1228 {
1229   GEOM::GEOM_Object_var aGEOMObject;
1230
1231   //Set a not done flag
1232   GetOperations()->SetNotDone();
1233
1234   //Get the reference shape
1235   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1236   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1237   Handle(::GEOM_Object) aDirection = GetObjectImpl(theDirection);
1238   if (aShape.IsNull() || aPoint.IsNull() || aDirection.IsNull()) return aGEOMObject._retn();
1239
1240   Handle(::GEOM_Object) anObject =
1241     GetOperations()->SurfaceCurvatureByPointAndDirection(aShape,aPoint,aDirection);
1242   if (!GetOperations()->IsDone() || anObject.IsNull())
1243     return aGEOMObject._retn();
1244
1245   return GetObject(anObject);
1246 }
1247
1248 //=============================================================================
1249 /*!
1250  *  XYZtoUV
1251  */
1252 //=============================================================================
1253 GEOM::ListOfDouble* GEOM_IMeasureOperations_i::XYZtoUV
1254                                         (GEOM::GEOM_Object_ptr     theSurf,
1255                                          const GEOM::ListOfDouble& theXYZlist,
1256                                          CORBA::Boolean            theIsNormalized)
1257 {
1258   GEOM::ListOfDouble_var resUV = new GEOM::ListOfDouble;
1259
1260   //Set a not done flag
1261   GetOperations()->SetNotDone();
1262
1263   //Get the reference shape
1264   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1265   if (aShape.IsNull()) return resUV._retn();
1266
1267   //Get input XYZ list
1268   Handle(TColStd_HArray1OfReal) aXYZlist =
1269     new TColStd_HArray1OfReal (0, theXYZlist.length() - 1);
1270   {
1271     size_t nb = theXYZlist.length(); 
1272     for (size_t i = 0; i < nb; ++i)
1273       aXYZlist->SetValue(i, theXYZlist[i]);
1274   }
1275
1276   //Call implementation
1277   Handle(TColStd_HArray1OfReal) aUVlist =
1278     GetOperations()->XYZtoUV(aShape, aXYZlist, theIsNormalized);
1279
1280   if (GetOperations()->IsDone()) {
1281     resUV->length(aUVlist->Length());
1282     int i0 = aUVlist->Lower();
1283     int nb = aUVlist->Upper(); 
1284     for (int i = i0; i <= nb; ++i)
1285       resUV[ i-i0 ] = aUVlist->Value(i);
1286   }
1287
1288   return resUV._retn();
1289 }
1290
1291 //=============================================================================
1292 /*!
1293  *  UVtoXYZ
1294  */
1295 //=============================================================================
1296 GEOM::ListOfDouble* GEOM_IMeasureOperations_i::UVtoXYZ
1297                                         (GEOM::GEOM_Object_ptr     theSurf,
1298                                          const GEOM::ListOfDouble& theUVlist,
1299                                          CORBA::Boolean            theIsNormalized)
1300 {
1301   GEOM::ListOfDouble_var resXYZ = new GEOM::ListOfDouble;
1302
1303   //Set a not done flag
1304   GetOperations()->SetNotDone();
1305
1306   //Get the reference shape
1307   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1308   if (aShape.IsNull()) return resXYZ._retn();
1309
1310   //Get input UV list
1311   Handle(TColStd_HArray1OfReal) aUVlist =
1312     new TColStd_HArray1OfReal (0, theUVlist.length() - 1);
1313   {
1314     size_t nb = theUVlist.length(); 
1315     for (size_t i = 0; i < nb; ++i)
1316       aUVlist->SetValue(i, theUVlist[i]);
1317   }
1318
1319   //Call implementation
1320   Handle(TColStd_HArray1OfReal) aXYZlist =
1321     GetOperations()->UVtoXYZ(aShape, aUVlist, theIsNormalized);
1322
1323   if (GetOperations()->IsDone()) {
1324     resXYZ->length(aXYZlist->Length());
1325     int i0 = aXYZlist->Lower();
1326     int nb = aXYZlist->Upper(); 
1327     for (int i = i0; i <= nb; ++i)
1328       resXYZ[ i-i0 ] = aXYZlist->Value(i);
1329   }
1330
1331   return resXYZ._retn();
1332 }
1333
1334 //=============================================================================
1335 /*!
1336  *  SelfIntersected2D
1337  *  Find all self-intersected 2D curves.
1338  *  \param theShape Shape for check.
1339  */
1340  //=============================================================================
1341 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::SelfIntersected2D(
1342                                           const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts)
1343 {
1344   GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1345     new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1346
1347   // Perform patch face operation
1348   std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1349   ConvertToList(theResuts, aResults);
1350
1351   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aSelfInters = GetOperations()->SelfIntersected2D(aResults);
1352   if (!GetOperations()->IsDone() || aSelfInters.empty())
1353     return aSeq._retn();
1354
1355   Standard_Integer aLength = aSelfInters.size();
1356   aSeq->length(aLength);
1357   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aSelfInters.begin());
1358   for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1359   {
1360     aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1361     aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1362   }
1363
1364   return aSeq._retn();
1365 }
1366
1367 //=============================================================================
1368 /*!
1369  *  InterferingSubshapes
1370  *  Find pairs of interfering sub-shapes, by default all pairs of interfering shapes are returned.
1371  *  \param theShape Shape for check.
1372  *  \param theShapeType1 Type of shape.
1373  *  \param theShapeType2 Type of shape.
1374  */
1375  //=============================================================================
1376 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::InterferingSubshapes(
1377     const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1378     const CORBA::Long theShapeType1,
1379     const CORBA::Long theShapeType2)
1380 {
1381   GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1382     new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1383
1384   // Perform patch face operation
1385   std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1386   ConvertToList(theResuts, aResults);
1387
1388   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aSelfInterf =
1389     GetOperations()->InterferingSubshapes(aResults, theShapeType1, theShapeType2);
1390   if (!GetOperations()->IsDone() || aSelfInterf.empty())
1391     return aSeq._retn();
1392
1393   Standard_Integer aLength = aSelfInterf.size();
1394   aSeq->length(aLength);
1395   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aSelfInterf.begin());
1396   for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1397   {
1398     aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1399     aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1400   }
1401
1402   return aSeq._retn();
1403 }
1404
1405 //=============================================================================
1406 /*!
1407  *  SmallEdges
1408  *  Find edges, which are fully covered by tolerances of vertices.
1409  *  \param theShape Shape for check.
1410  */
1411  //=============================================================================
1412 GEOM::ListOfGO* GEOM_IMeasureOperations_i::SmallEdges(const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts)
1413 {
1414   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1415
1416   std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1417   ConvertToList(theResuts, aResults);
1418
1419   //Get the reference shape
1420   Handle(TColStd_HSequenceOfTransient) aSmallEdges = GetOperations()->SmallEdges(aResults);
1421   if (!GetOperations()->IsDone() || aSmallEdges.IsNull())
1422     return aSeq._retn();
1423
1424   Standard_Integer aLength = aSmallEdges->Length();
1425   aSeq->length(aLength);
1426   for (Standard_Integer i = 1; i <= aLength; i++)
1427     aSeq[i - 1] = GetObject(Handle(::GEOM_Object)::DownCast(aSmallEdges->Value(i)));
1428
1429   return aSeq._retn();
1430 }
1431
1432 //=============================================================================
1433 /*!
1434  *  DistantShapes
1435  *  find remote objects (sub-shape on a shape).
1436  *  \param theShape Shape for check.
1437  *  \param theShapeType Type of shape.
1438  *  \param theSubShapeType Type of sub-shape.
1439  *  \param theTolerance tolerance.
1440  */
1441  //=============================================================================
1442 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::DistantShapes(
1443     const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1444     const CORBA::Long theShapeType,
1445     const CORBA::Long theSubShapeType,
1446     const CORBA::Double theTolerance)
1447 {
1448   GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1449     new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1450
1451   std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1452   ConvertToList(theResuts, aResults);
1453
1454   // Perform patch face operation
1455   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aDistantS =
1456       GetOperations()->DistantShapes(aResults, theShapeType, theSubShapeType, theTolerance);
1457   if (!GetOperations()->IsDone() || aDistantS.empty())
1458     return aSeq._retn();
1459
1460   Standard_Integer aLength = aDistantS.size();
1461   aSeq->length(aLength);
1462   std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aDistantS.begin());
1463   for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1464   {
1465     aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1466     aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1467   }
1468
1469   return aSeq._retn();
1470 }
1471
1472 //=============================================================================
1473 /*!
1474  *  CheckConformityShape
1475  *  Perform all required checks
1476  */
1477  //=============================================================================
1478 GEOM::GEOM_IMeasureOperations::CheckResults* GEOM_IMeasureOperations_i::CheckConformityShape(
1479     GEOM::GEOM_Object_ptr theShape)
1480 {
1481   GEOM::GEOM_IMeasureOperations::CheckResults_var aRes = new GEOM::GEOM_IMeasureOperations::CheckResults;
1482
1483   //Get the reference shape
1484   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1485   if (aShapeRef.IsNull()) return nullptr;
1486
1487   std::list<GEOMImpl_IMeasureOperations::FailedChecks> aChecks;
1488   GetOperations()->CheckConformityShape(aShapeRef, aChecks);
1489
1490   Standard_Integer aLength = aChecks.size();
1491   aRes->length(aLength);
1492   std::list<GEOMImpl_IMeasureOperations::FailedChecks>::const_iterator anIntIt = aChecks.cbegin();
1493   for (Standard_Integer i = 0; i < aLength; i++, ++anIntIt)
1494   {
1495     aRes[i].type = (*anIntIt).TypeOfCheck;
1496     aRes[i].failedShapes.first  = GetObject(Handle(::GEOM_Object)::DownCast((*anIntIt).FailedShapes.first));
1497     aRes[i].failedShapes.second = GetObject(Handle(::GEOM_Object)::DownCast((*anIntIt).FailedShapes.second));
1498   }
1499
1500   return aRes._retn();
1501 }
1502
1503 //=============================================================================
1504 /*!
1505  *  UpdateTolerance
1506  *  Compute possible tolerance for the shape, minimize tolerance of shape as well
1507  *  as tolerance of sub-shapes as much as possible
1508  *  \param theShape Shape for check.
1509  */
1510  //=============================================================================
1511 CORBA::Double GEOM_IMeasureOperations_i::UpdateTolerance(GEOM::GEOM_Object_ptr theShape)
1512 {
1513   //Get the reference shape
1514   Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1515   if (aShapeRef.IsNull())
1516     return false;
1517
1518   return GetOperations()->UpdateTolerance(aShapeRef);
1519 }
1520
1521 void GEOM_IMeasureOperations_i::ConvertToList(const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1522                                               std::list<GEOMImpl_IMeasureOperations::FailedChecks>& theListOfResults)
1523 {
1524   for (Standard_Integer i = 0; i < theResuts.length(); ++i)
1525   {
1526     GEOMImpl_IMeasureOperations::FailedChecks aCheck;
1527     aCheck.TypeOfCheck = theResuts[i].type;
1528     aCheck.FailedShapes.first = GetObjectImpl(theResuts[i].failedShapes.first);
1529     aCheck.FailedShapes.second = GetObjectImpl(theResuts[i].failedShapes.second);
1530     theListOfResults.push_back(aCheck);
1531   }
1532 }
1533
1534 //=============================================================================
1535 /*!
1536  *  ShapeProximityCalculator
1537  */
1538 //=============================================================================
1539 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::ShapeProximityCalculator(GEOM::GEOM_Object_ptr theShape1,
1540                                                                           GEOM::GEOM_Object_ptr theShape2)
1541 {
1542   GEOM::GEOM_Object_var anEmptyCalc;
1543
1544   //Set a not done flag
1545   GetOperations()->SetNotDone();
1546
1547   //Get the reference shape
1548   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1549   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1550   if (aShape1.IsNull() || aShape2.IsNull())
1551     return anEmptyCalc._retn();
1552
1553   Handle(::GEOM_Object) aCalculator = GetOperations()->ShapeProximityCalculator(aShape1, aShape2);
1554   if (!GetOperations()->IsDone() || aCalculator.IsNull())
1555     return anEmptyCalc._retn();
1556
1557   return GetObject(aCalculator);
1558 }
1559
1560 //=============================================================================
1561 /*!
1562  *  SetShapeSampling
1563  */
1564  //=============================================================================
1565 void GEOM_IMeasureOperations_i::SetShapeSampling(GEOM::GEOM_Object_ptr theCalculator,
1566                                                  GEOM::GEOM_Object_ptr theShape,
1567                                                  CORBA::Long theNbSamples)
1568 {
1569   //Set a not done flag
1570   GetOperations()->SetNotDone();
1571
1572   //Get the proximity calculator
1573   Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1574   if (aCalc.IsNull())
1575     return ;
1576   //Get the reference shape
1577   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1578   if (aShape.IsNull())
1579     return ;
1580
1581   GetOperations()->SetShapeSampling(aCalc, aShape, theNbSamples);
1582 }
1583
1584 //=============================================================================
1585 /*!
1586  *  GetCoarseProximity
1587  */
1588  //=============================================================================
1589 CORBA::Double GEOM_IMeasureOperations_i::GetCoarseProximity(GEOM::GEOM_Object_ptr theCalculator)
1590 {
1591   //Set a not done flag
1592   GetOperations()->SetNotDone();
1593
1594   //Get the reference shape
1595   Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1596   if (aCalc.IsNull())
1597     return -1.0;
1598
1599   Standard_Real aProximity = GetOperations()->GetCoarseProximity(aCalc);
1600   if (!GetOperations()->IsDone())
1601     return -1.0;
1602
1603   return aProximity;
1604 }
1605
1606 //=============================================================================
1607 /*!
1608  *  GetPreciseProximity
1609  */
1610  //=============================================================================
1611 CORBA::Double GEOM_IMeasureOperations_i::GetPreciseProximity(GEOM::GEOM_Object_ptr theCalculator)
1612 {
1613   //Set a not done flag
1614   GetOperations()->SetNotDone();
1615
1616   //Get the reference shape
1617   Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1618   if (aCalc.IsNull())
1619     return -1.0;
1620
1621   Standard_Real aProximity = GetOperations()->GetPreciseProximity(aCalc);
1622   if (!GetOperations()->IsDone())
1623     return -1.0;
1624
1625   return aProximity;
1626 }