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