Salome HOME
Typo-fix by Kunda
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 // Copyright (C) 2007-2016  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
25 #include "GEOM_IMeasureOperations_i.hh"
26
27 #include "utilities.h"
28 #include "OpUtil.hxx"
29
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
32
33 /**
34  * This function converts shape errors from theErrorsFrom to theErrorsTo.
35  * Note that theErrorsTo is not cleared at first.
36  *
37  * \param theErrorsFrom errors to be converted.
38  * \param theErrorsTo result errors.
39  */
40 static void ConvertShapeError
41     (const GEOM::GEOM_IMeasureOperations::ShapeErrors         &theErrorsFrom,
42            std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsTo)
43 {
44   int aNbErr = theErrorsFrom.length();
45   int i = 0;
46
47   for (; i < aNbErr; i++) {
48     const GEOM::GEOM_IMeasureOperations::ShapeError anErr = theErrorsFrom[i];
49     const GEOM::GEOM_IMeasureOperations::ShapeErrorType aType = anErr.error;
50     const GEOM::ListOfLong anIncrims = anErr.incriminated;
51     GEOMImpl_IMeasureOperations::ShapeError anErrStruct;
52
53     switch (aType) {
54     case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve:
55       anErrStruct.error = BRepCheck_InvalidPointOnCurve;
56       break;
57     case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface:
58       anErrStruct.error = BRepCheck_InvalidPointOnCurveOnSurface;
59       break;
60     case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface:
61       anErrStruct.error = BRepCheck_InvalidPointOnSurface;
62       break;
63     case GEOM::GEOM_IMeasureOperations::No3DCurve:
64       anErrStruct.error = BRepCheck_No3DCurve;
65       break;
66     case GEOM::GEOM_IMeasureOperations::Multiple3DCurve:
67       anErrStruct.error = BRepCheck_Multiple3DCurve;
68       break;
69     case GEOM::GEOM_IMeasureOperations::Invalid3DCurve:
70       anErrStruct.error = BRepCheck_Invalid3DCurve;
71       break;
72     case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface:
73       anErrStruct.error = BRepCheck_NoCurveOnSurface;
74       break;
75     case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface:
76       anErrStruct.error = BRepCheck_InvalidCurveOnSurface;
77       break;
78     case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface:
79       anErrStruct.error = BRepCheck_InvalidCurveOnClosedSurface;
80       break;
81     case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag:
82       anErrStruct.error = BRepCheck_InvalidSameRangeFlag;
83       break;
84     case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag:
85       anErrStruct.error = BRepCheck_InvalidSameParameterFlag;
86       break;
87     case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag:
88       anErrStruct.error = BRepCheck_InvalidDegeneratedFlag;
89       break;
90     case GEOM::GEOM_IMeasureOperations::FreeEdge:
91       anErrStruct.error = BRepCheck_FreeEdge;
92       break;
93     case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity:
94       anErrStruct.error = BRepCheck_InvalidMultiConnexity;
95       break;
96     case GEOM::GEOM_IMeasureOperations::InvalidRange:
97       anErrStruct.error = BRepCheck_InvalidRange;
98       break;
99     case GEOM::GEOM_IMeasureOperations::EmptyWire:
100       anErrStruct.error = BRepCheck_EmptyWire;
101       break;
102     case GEOM::GEOM_IMeasureOperations::RedundantEdge:
103       anErrStruct.error = BRepCheck_RedundantEdge;
104       break;
105     case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire:
106       anErrStruct.error = BRepCheck_SelfIntersectingWire;
107       break;
108     case GEOM::GEOM_IMeasureOperations::NoSurface:
109       anErrStruct.error = BRepCheck_NoSurface;
110       break;
111     case GEOM::GEOM_IMeasureOperations::InvalidWire:
112       anErrStruct.error = BRepCheck_InvalidWire;
113       break;
114     case GEOM::GEOM_IMeasureOperations::RedundantWire:
115       anErrStruct.error = BRepCheck_RedundantWire;
116       break;
117     case GEOM::GEOM_IMeasureOperations::IntersectingWires:
118       anErrStruct.error = BRepCheck_IntersectingWires;
119       break;
120     case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires:
121       anErrStruct.error = BRepCheck_InvalidImbricationOfWires;
122       break;
123     case GEOM::GEOM_IMeasureOperations::EmptyShell:
124       anErrStruct.error = BRepCheck_EmptyShell;
125       break;
126     case GEOM::GEOM_IMeasureOperations::RedundantFace:
127       anErrStruct.error = BRepCheck_RedundantFace;
128       break;
129     case GEOM::GEOM_IMeasureOperations::UnorientableShape:
130       anErrStruct.error = BRepCheck_UnorientableShape;
131       break;
132     case GEOM::GEOM_IMeasureOperations::NotClosed:
133       anErrStruct.error = BRepCheck_NotClosed;
134       break;
135     case GEOM::GEOM_IMeasureOperations::NotConnected:
136       anErrStruct.error = BRepCheck_NotConnected;
137       break;
138     case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape:
139       anErrStruct.error = BRepCheck_SubshapeNotInShape;
140       break;
141     case GEOM::GEOM_IMeasureOperations::BadOrientation:
142       anErrStruct.error = BRepCheck_BadOrientation;
143       break;
144     case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape:
145       anErrStruct.error = BRepCheck_BadOrientationOfSubshape;
146       break;
147     case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue:
148       anErrStruct.error = BRepCheck_InvalidToleranceValue;
149       break;
150     case GEOM::GEOM_IMeasureOperations::CheckFail:
151       anErrStruct.error = BRepCheck_CheckFail;
152       break;
153     default:
154       break;
155     }
156
157     int ii = 0;
158     int aLen = anIncrims.length();
159
160     for (; ii < aLen; ii++) {
161       anErrStruct.incriminated.push_back(anIncrims[ii]);
162     }
163
164     theErrorsTo.push_back(anErrStruct);
165   }
166 }
167
168 /**
169  * This function converts shape errors from theErrorsFrom to theErrorsTo.
170  * Note that theErrorsTo is not cleared at first.
171  *
172  * \param theErrorsFrom errors to be converted.
173  * \param theErrorsTo result errors.
174  */
175 static void ConvertShapeError
176     (const std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsFrom,
177            GEOM::GEOM_IMeasureOperations::ShapeErrors_out     &theErrorsTo)
178 {
179   const int aNbErr = theErrorsFrom.size();
180   GEOM::GEOM_IMeasureOperations::ShapeErrors_var anErrArray =
181     new GEOM::GEOM_IMeasureOperations::ShapeErrors;
182
183   anErrArray->length(aNbErr);
184
185   // fill the local CORBA array with values from lists
186   std::list<GEOMImpl_IMeasureOperations::ShapeError>::const_iterator
187     anIt = theErrorsFrom.begin();
188   int i = 0;
189
190   for (; anIt != theErrorsFrom.end(); i++, anIt++) {
191     GEOM::GEOM_IMeasureOperations::ShapeError_var anErrStruct =
192       new GEOM::GEOM_IMeasureOperations::ShapeError;
193
194     switch (anIt->error) {
195     case BRepCheck_InvalidPointOnCurve:
196       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve;
197       break;
198     case BRepCheck_InvalidPointOnCurveOnSurface:
199       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface;
200       break;
201     case BRepCheck_InvalidPointOnSurface:
202       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface;
203       break;
204     case BRepCheck_No3DCurve:
205       anErrStruct->error = GEOM::GEOM_IMeasureOperations::No3DCurve;
206       break;
207     case BRepCheck_Multiple3DCurve:
208       anErrStruct->error = GEOM::GEOM_IMeasureOperations::Multiple3DCurve;
209       break;
210     case BRepCheck_Invalid3DCurve:
211       anErrStruct->error = GEOM::GEOM_IMeasureOperations::Invalid3DCurve;
212       break;
213     case BRepCheck_NoCurveOnSurface:
214       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoCurveOnSurface;
215       break;
216     case BRepCheck_InvalidCurveOnSurface:
217       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface;
218       break;
219     case BRepCheck_InvalidCurveOnClosedSurface:
220       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface;
221       break;
222     case BRepCheck_InvalidSameRangeFlag:
223       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag;
224       break;
225     case BRepCheck_InvalidSameParameterFlag:
226       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag;
227       break;
228     case BRepCheck_InvalidDegeneratedFlag:
229       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag;
230       break;
231     case BRepCheck_FreeEdge:
232       anErrStruct->error = GEOM::GEOM_IMeasureOperations::FreeEdge;
233       break;
234     case BRepCheck_InvalidMultiConnexity:
235       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity;
236       break;
237     case BRepCheck_InvalidRange:
238       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidRange;
239       break;
240     case BRepCheck_EmptyWire:
241       anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyWire;
242       break;
243     case BRepCheck_RedundantEdge:
244       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantEdge;
245       break;
246     case BRepCheck_SelfIntersectingWire:
247       anErrStruct->error = GEOM::GEOM_IMeasureOperations::SelfIntersectingWire;
248       break;
249     case BRepCheck_NoSurface:
250       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoSurface;
251       break;
252     case BRepCheck_InvalidWire:
253       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidWire;
254       break;
255     case BRepCheck_RedundantWire:
256       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantWire;
257       break;
258     case BRepCheck_IntersectingWires:
259       anErrStruct->error = GEOM::GEOM_IMeasureOperations::IntersectingWires;
260       break;
261     case BRepCheck_InvalidImbricationOfWires:
262       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires;
263       break;
264     case BRepCheck_EmptyShell:
265       anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyShell;
266       break;
267     case BRepCheck_RedundantFace:
268       anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantFace;
269       break;
270     case BRepCheck_UnorientableShape:
271       anErrStruct->error = GEOM::GEOM_IMeasureOperations::UnorientableShape;
272       break;
273     case BRepCheck_NotClosed:
274       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotClosed;
275       break;
276     case BRepCheck_NotConnected:
277       anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotConnected;
278       break;
279     case BRepCheck_SubshapeNotInShape:
280       anErrStruct->error = GEOM::GEOM_IMeasureOperations::SubshapeNotInShape;
281       break;
282     case BRepCheck_BadOrientation:
283       anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientation;
284       break;
285     case BRepCheck_BadOrientationOfSubshape:
286       anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape;
287       break;
288     case BRepCheck_InvalidToleranceValue:
289       anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidToleranceValue;
290       break;
291     case BRepCheck_CheckFail:
292       anErrStruct->error = GEOM::GEOM_IMeasureOperations::CheckFail;
293       break;
294     default:
295       break;
296     }
297
298     std::list<int> aIndList = anIt->incriminated;
299     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
300     anIncrims->length(aIndList.size());
301
302     std::list<int>::iterator anIndIt = aIndList.begin();
303     int jj = 0;
304
305     for (; anIndIt != aIndList.end(); jj++, anIndIt++) {
306       anIncrims[jj] = *anIndIt;
307     }
308
309     anErrStruct->incriminated = anIncrims;
310
311     anErrArray[i] = anErrStruct;
312   }
313
314   // initialize out-parameter with local array
315   theErrorsTo = anErrArray._retn();
316 }
317
318 //=============================================================================
319 /*!
320  *   constructor:
321  */
322 //=============================================================================
323 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
324                                                       GEOM::GEOM_Gen_ptr theEngine,
325                                                       ::GEOMImpl_IMeasureOperations* theImpl)
326 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
327 {
328   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
329 }
330
331 //=============================================================================
332 /*!
333  *  destructor
334  */
335 //=============================================================================
336 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
337 {
338   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
339 }
340
341 //=============================================================================
342 /*!
343  *  KindOfShape
344  */
345 //=============================================================================
346 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
347                                    (GEOM::GEOM_Object_ptr  theShape,
348                                     GEOM::ListOfLong_out   theIntegers,
349                                     GEOM::ListOfDouble_out theDoubles)
350 {
351   GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
352
353   // allocate the CORBA arrays
354   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
355   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
356
357   //Get the reference shape
358   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
359
360   if (!aShape.IsNull()) {
361     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
362     Handle(TColStd_HSequenceOfReal)    aDoubles   = new TColStd_HSequenceOfReal;
363
364     // Detect kind of shape and parameters
365     aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
366
367     int nbInts = anIntegers->Length();
368     int nbDbls = aDoubles->Length();
369
370     anIntegersArray->length(nbInts);
371     aDoublesArray->length(nbDbls);
372
373     for (int ii = 0; ii < nbInts; ii++) {
374       anIntegersArray[ii] = anIntegers->Value(ii + 1);
375     }
376     for (int id = 0; id < nbDbls; id++) {
377       aDoublesArray[id] = aDoubles->Value(id + 1);
378     }
379   }
380
381   // initialize out-parameters with local arrays
382   theIntegers = anIntegersArray._retn();
383   theDoubles  = aDoublesArray._retn();
384   return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
385 }
386
387 //=============================================================================
388 /*!
389  *  GetPosition
390  */
391 //=============================================================================
392 void GEOM_IMeasureOperations_i::GetPosition
393                  (GEOM::GEOM_Object_ptr theShape,
394                   CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
395                   CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
396                   CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
397 {
398   //Set a not done flag
399   GetOperations()->SetNotDone();
400
401   //Set default values: global CS
402   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
403   Zz = Xx = 1.;
404
405   //Get the reference shape
406   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
407   if (aShape.IsNull()) return;
408
409   // Get shape parameters
410   GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
411 }
412
413 //=============================================================================
414 /*!
415  *  GetCentreOfMass
416  */
417 //=============================================================================
418 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
419                                               (GEOM::GEOM_Object_ptr theShape)
420 {
421   GEOM::GEOM_Object_var aGEOMObject;
422
423   //Set a not done flag
424   GetOperations()->SetNotDone();
425
426   //Get the reference shape
427   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
428   if (aShape.IsNull()) return aGEOMObject._retn();
429
430   // Make Point - centre of mass of theShape
431   Handle(::GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
432   if (!GetOperations()->IsDone() || anObject.IsNull())
433     return aGEOMObject._retn();
434
435   return GetObject(anObject);
436 }
437
438 //=============================================================================
439 /*!
440  *  GetVertexByIndex
441  */
442 //=============================================================================
443 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex
444   (GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex)
445 {
446   GEOM::GEOM_Object_var aGEOMObject;
447
448   //Set a not done flag
449   GetOperations()->SetNotDone();
450
451   //Get the reference shape
452   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
453   if ( aShape.IsNull() ) return aGEOMObject._retn();
454
455   // Get vertex by index
456   Handle(::GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex);
457   if (!GetOperations()->IsDone() || anObject.IsNull())
458     return aGEOMObject._retn();
459
460   return GetObject(anObject);
461 }
462
463 //=============================================================================
464 /*!
465  *  GetNormal
466  */
467 //=============================================================================
468 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
469                                        (GEOM::GEOM_Object_ptr theFace,
470                                         GEOM::GEOM_Object_ptr theOptionalPoint)
471 {
472   GEOM::GEOM_Object_var aGEOMObject;
473
474   //Set a not done flag
475   GetOperations()->SetNotDone();
476
477   //Get the reference shape
478   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
479   if (aFace.IsNull()) return aGEOMObject._retn();
480
481   // Get the OptionalPoint (can be not defined)
482   Handle(::GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
483
484   // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
485   Handle(::GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
486   if (!GetOperations()->IsDone() || anObject.IsNull())
487     return aGEOMObject._retn();
488
489   return GetObject(anObject);
490 }
491
492 //=============================================================================
493 /*!
494  *  GetBasicProperties
495  */
496 //=============================================================================
497 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
498                                                     CORBA::Double  theTolerance,
499                                                     CORBA::Double& theLength,
500                                                     CORBA::Double& theSurfArea,
501                                                     CORBA::Double& theVolume)
502 {
503   //Set a not done flag
504   GetOperations()->SetNotDone();
505
506   //Get the reference shape
507   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
508   if (aShape.IsNull()) return;
509
510   // Get shape parameters
511   GetOperations()->GetBasicProperties(aShape, theTolerance, theLength,
512                                       theSurfArea, theVolume);
513 }
514
515 //=============================================================================
516 /*!
517  *  GetInertia
518  */
519 //=============================================================================
520 void GEOM_IMeasureOperations_i::GetInertia
521   (GEOM::GEOM_Object_ptr theShape,
522    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
523    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
524    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
525    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
526 {
527   //Set a not done flag
528   GetOperations()->SetNotDone();
529
530   //Get the reference shape
531   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
532   if (aShape.IsNull()) return;
533
534   // Get shape parameters
535   GetOperations()->GetInertia(aShape,
536                               I11, I12, I13,
537                               I21, I22, I23,
538                               I31, I32, I33,
539                               Ix , Iy , Iz);
540 }
541
542 //=============================================================================
543 /*!
544  *  GetBoundingBox
545  */
546 //=============================================================================
547 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
548                                                 CORBA::Boolean precise,
549                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
550                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
551                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
552 {
553   //Set a not done flag
554   GetOperations()->SetNotDone();
555
556   //Get the reference shape
557   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
558   if (aShape.IsNull()) return;
559
560   // Get shape parameters
561   GetOperations()->GetBoundingBox
562     (aShape, precise, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
563 }
564
565 //=============================================================================
566 /*!
567  *  MakeBoundingBox
568  */
569 //=============================================================================
570 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
571                                               (GEOM::GEOM_Object_ptr theShape,
572                                                CORBA::Boolean precise)
573 {
574   GEOM::GEOM_Object_var aGEOMObject;
575
576   //Set a not done flag
577   GetOperations()->SetNotDone();
578
579   //Get the reference shape
580   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
581   if (aShape.IsNull()) return aGEOMObject._retn();
582
583   // Make Box - bounding box of theShape
584   Handle(::GEOM_Object) anObject =
585     GetOperations()->GetBoundingBox(aShape, precise);
586   if (!GetOperations()->IsDone() || anObject.IsNull())
587     return aGEOMObject._retn();
588
589   return GetObject(anObject);
590 }
591
592 //=============================================================================
593 /*!
594  *  GetTolerance
595  */
596 //=============================================================================
597 void GEOM_IMeasureOperations_i::GetTolerance
598                                 (GEOM::GEOM_Object_ptr theShape,
599                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
600                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
601                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
602 {
603   //Set a not done flag
604   GetOperations()->SetNotDone();
605
606   //Get the reference shape
607   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
608   if (aShape.IsNull()) return;
609
610   // Get shape parameters
611   GetOperations()->GetTolerance(aShape,
612                                 FaceMin, FaceMax,
613                                 EdgeMin, EdgeMax,
614                                 VertMin, VertMax);
615 }
616
617 //=============================================================================
618 /*!
619  *  CheckShape
620  */
621 //=============================================================================
622 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape
623              (GEOM::GEOM_Object_ptr                          theShape,
624               GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
625 {
626   //Set a not done flag
627   GetOperations()->SetNotDone();
628
629   if (CORBA::is_nil(theShape))
630   {
631     return 0;
632   }
633
634   //Get the reference shape
635   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
636
637   if (aShape.IsNull())
638   {
639     return 0;
640   }
641
642   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
643   bool isOk = GetOperations()->CheckShape(aShape, false, anErrList);
644
645   ConvertShapeError(anErrList, theErrors);
646
647   return isOk;
648 }
649
650 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry
651              (GEOM::GEOM_Object_ptr                          theShape,
652               GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
653 {
654   //Set a not done flag
655   GetOperations()->SetNotDone();
656
657   if (CORBA::is_nil(theShape))
658   {
659     return 0;
660   }
661
662   //Get the reference shape
663   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
664
665   if (aShape.IsNull())
666   {
667     return 0;
668   }
669
670   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
671   bool isOk = GetOperations()->CheckShape(aShape, true, anErrList);
672
673   ConvertShapeError(anErrList, theErrors);
674
675   return isOk;
676 }
677
678 //=============================================================================
679 /*!
680  *  PrintShapeErrors
681  */
682 //=============================================================================
683 char* GEOM_IMeasureOperations_i::PrintShapeErrors
684              (      GEOM::GEOM_Object_ptr                       theShape,
685               const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors)
686 {
687   //Get the reference shape
688   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
689
690   if (aShape.IsNull()) {
691     return NULL;
692   }
693
694   // Convert the errors sequence
695   std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
696
697   ConvertShapeError(theErrors, anErrList);
698
699   TCollection_AsciiString aDescr =
700     GetOperations()->PrintShapeErrors(aShape, anErrList);
701
702   return CORBA::string_dup(aDescr.ToCString());
703 }
704
705 //=============================================================================
706 /*!
707  *  CheckSelfIntersections
708  */
709 //=============================================================================
710 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
711                                                                   CORBA::Long           theCheckLevel,
712                                                                   GEOM::ListOfLong_out  theIntersections)
713 {
714   // Set a not done flag
715   GetOperations()->SetNotDone();
716
717   bool isGood = false;
718
719   // Allocate the CORBA arrays
720   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
721
722   // Get the reference shape
723   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
724
725   if (!aShape.IsNull()) {
726     GEOMImpl_IMeasureOperations::SICheckLevel aCheckLevel;
727
728     switch(theCheckLevel) {
729     case GEOM::SI_V_V:
730       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_V;
731       break;
732     case GEOM::SI_V_E:
733       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_E;
734       break;
735     case GEOM::SI_E_E:
736       aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_E;
737       break;
738     case GEOM::SI_V_F:
739       aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_F;
740       break;
741     case GEOM::SI_E_F:
742       aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_F;
743       break;
744     case GEOM::SI_ALL:
745     default:
746       aCheckLevel = GEOMImpl_IMeasureOperations::SI_ALL;
747       break;
748     }
749
750     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
751
752     // Detect self-intersections
753     isGood = GetOperations()->CheckSelfIntersections
754       (aShape, aCheckLevel, anIntegers);
755
756     int nbInts = anIntegers->Length();
757
758     anIntegersArray->length(nbInts);
759
760     for (int ii = 0; ii < nbInts; ii++) {
761       anIntegersArray[ii] = anIntegers->Value(ii + 1);
762     }
763   }
764
765   // Initialize out-parameters with local arrays
766   theIntersections = anIntegersArray._retn();
767   return isGood;
768 }
769
770 //=============================================================================
771 /*!
772  *  CheckSelfIntersectionsFast
773  */
774 //=============================================================================
775 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersectionsFast 
776   (GEOM::GEOM_Object_ptr theShape,
777    CORBA::Float          theDeflection,
778    CORBA::Double         theTolerance,
779    GEOM::ListOfLong_out  theIntersections)
780 {
781   // Set a not done flag
782   GetOperations()->SetNotDone();
783
784   bool isGood = false;
785
786   // Allocate the CORBA arrays
787   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
788
789   // Get the reference shape
790   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
791
792   if (!aShape.IsNull()) {
793     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
794
795     // Detect self-intersections
796     isGood = GetOperations()->CheckSelfIntersectionsFast
797       (aShape, theDeflection, theTolerance, anIntegers);
798
799     int nbInts = anIntegers->Length();
800
801     anIntegersArray->length(nbInts);
802
803     for (int ii = 0; ii < nbInts; ii++) {
804       anIntegersArray[ii] = anIntegers->Value(ii + 1);
805     }
806   }
807
808   // Initialize out-parameters with local arrays
809   theIntersections = anIntegersArray._retn();
810   return isGood;
811 }
812
813 //=============================================================================
814 /*!
815  *  CheckBOPArguments
816  */
817 //=============================================================================
818 CORBA::Boolean GEOM_IMeasureOperations_i::CheckBOPArguments
819                                       (GEOM::GEOM_Object_ptr theShape)
820 {
821   // Set a not done flag
822   GetOperations()->SetNotDone();
823
824   // Get the reference shape
825   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
826   bool isGood = false;
827
828   if (!aShape.IsNull()) {
829     // Check BOP arguments
830     isGood = GetOperations()->CheckBOPArguments(aShape);
831   }
832
833   return isGood;
834 }
835
836 //=============================================================================
837 /*!
838  *  FastIntersect
839  */
840 //=============================================================================
841 CORBA::Boolean GEOM_IMeasureOperations_i::FastIntersect (GEOM::GEOM_Object_ptr theShape1,
842                                                          GEOM::GEOM_Object_ptr theShape2,
843                                                          CORBA::Double         theTolerance,
844                                                          CORBA::Float          theDeflection,
845                                                          GEOM::ListOfLong_out  theIntersections1,
846                                                          GEOM::ListOfLong_out  theIntersections2)
847 {
848   // Set a not done flag
849   GetOperations()->SetNotDone();
850
851   bool isGood = false;
852
853   // Allocate the CORBA arrays
854   GEOM::ListOfLong_var anIntegersArray1 = new GEOM::ListOfLong();
855   GEOM::ListOfLong_var anIntegersArray2 = new GEOM::ListOfLong();
856
857   // Get the reference shape
858   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
859   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
860   
861   if (!aShape1.IsNull() && !aShape2.IsNull()) {
862     Handle(TColStd_HSequenceOfInteger) anIntegers1 = new TColStd_HSequenceOfInteger;
863     Handle(TColStd_HSequenceOfInteger) anIntegers2 = new TColStd_HSequenceOfInteger;
864
865     // Detect intersections
866     isGood = GetOperations()->FastIntersect
867       (aShape1, aShape2, theTolerance, theDeflection, anIntegers1, anIntegers2);
868
869     int nbInts1 = anIntegers1->Length();
870     int nbInts2 = anIntegers2->Length();
871
872     anIntegersArray1->length(nbInts1);
873     anIntegersArray2->length(nbInts2);
874
875     for (int ii = 0; ii < nbInts1; ii++) {
876       anIntegersArray1[ii] = anIntegers1->Value(ii + 1);
877     }
878     for (int ii = 0; ii < nbInts2; ii++) {
879       anIntegersArray2[ii] = anIntegers2->Value(ii + 1);
880     }
881   }
882
883   // Initialize out-parameters with local arrays
884   theIntersections1 = anIntegersArray1._retn();
885   theIntersections2 = anIntegersArray2._retn();
886   return isGood;
887 }
888
889 //=============================================================================
890 /*!
891  *  IsGoodForSolid
892  */
893 //=============================================================================
894 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
895 {
896   //Set a not done flag
897   GetOperations()->SetNotDone();
898
899   //Get the reference shape
900   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
901   if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
902
903   // Get shape parameters
904   TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
905   return CORBA::string_dup(aDescription.ToCString());
906 }
907
908 //=============================================================================
909 /*!
910  *  WhatIs
911  */
912 //=============================================================================
913 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
914 {
915   //Set a not done flag
916   GetOperations()->SetNotDone();
917
918   //Get the reference shape
919   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
920   if (aShape.IsNull()) return NULL;
921
922   // Get shape parameters
923   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
924   return CORBA::string_dup(aDescription.ToCString());
925 }
926
927 //=============================================================================
928 /*!
929  *  AreCoordsInside
930  */
931 //=============================================================================
932 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
933                                                               const GEOM::ListOfDouble& theCoords,
934                                                               CORBA::Double tolerance)
935 {
936   //Set a not done flag
937   GetOperations()->SetNotDone();
938   
939   int nb_points = theCoords.length()/3;
940
941   GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
942   aResults->length(nb_points);
943   
944   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
945   
946   std::vector<double> tmp(3*nb_points);
947   for (int i = 0; i < 3*nb_points; i++)
948     tmp[i] = theCoords[i];
949   std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
950   for (int i = 0, resSize = res.size();  i < nb_points; i++)
951     aResults[i] = i < resSize ? res[i] : false;
952   return aResults._retn();
953 }
954
955 //=============================================================================
956 /*!
957  *  GetMinDistance
958  */
959 //=============================================================================
960 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
961   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
962    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
963    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
964 {
965   //Set a not done flag
966   GetOperations()->SetNotDone();
967
968   //Get the reference shape
969   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
970   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
971   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
972
973   // Get shape parameters
974   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
975 }
976
977 //=============================================================================
978 /*!
979  *  ClosestPoints
980  */
981 //=============================================================================
982 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
983   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
984    GEOM::ListOfDouble_out theCoords)
985 {
986   //Set a not done flag
987   GetOperations()->SetNotDone();
988
989   // allocate the CORBA array
990   int nbSols = 0;
991   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
992
993   //Get the reference shape
994   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
995   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
996
997   if (!aShape1.IsNull() && !aShape2.IsNull()) {
998     Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
999     // Get shape parameters
1000     nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
1001     int nbDbls = aDoubles->Length();
1002     aDoublesArray->length(nbDbls);
1003     for (int id = 0; id < nbDbls; id++) {
1004       aDoublesArray[id] = aDoubles->Value(id + 1);
1005     }
1006   }
1007
1008   theCoords = aDoublesArray._retn();
1009   return nbSols;
1010 }
1011
1012 //=============================================================================
1013 /*!
1014  *  PointCoordinates
1015  */
1016 //=============================================================================
1017 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
1018                                                   CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
1019
1020 {
1021   //Set a not done flag
1022   GetOperations()->SetNotDone();
1023
1024   //Get the reference shape
1025   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1026   if (aShape.IsNull())
1027     return;
1028
1029   // Get shape parameters
1030   GetOperations()->PointCoordinates( aShape, X, Y, Z );
1031 }
1032
1033 //=============================================================================
1034 /*!
1035  *  GetAngle
1036  */
1037 //=============================================================================
1038 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
1039                                                    GEOM::GEOM_Object_ptr theShape2)
1040 {
1041   //Set a not done flag
1042   GetOperations()->SetNotDone();
1043
1044   //Get the reference shapes
1045   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1046   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1047   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1048
1049   // Get the angle
1050   return GetOperations()->GetAngle(aShape1, aShape2);
1051 }
1052
1053 //=============================================================================
1054 /*!
1055  *  GetAngle
1056  */
1057 //=============================================================================
1058 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
1059                                                              GEOM::GEOM_Object_ptr theShape2)
1060 {
1061   //Set a not done flag
1062   GetOperations()->SetNotDone();
1063
1064   //Get the reference shapes
1065   Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1066   Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1067   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1068
1069   // Get the angle
1070   return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
1071 }
1072
1073
1074 //=============================================================================
1075 /*!
1076  *  CurveCurvatureByParam
1077  */
1078 //=============================================================================
1079 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
1080                        (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
1081 {
1082   //Set a not done flag
1083   GetOperations()->SetNotDone();
1084
1085   //Get the reference shape
1086   Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1087   if(aShape.IsNull()) return -1.0;
1088
1089   return GetOperations()->CurveCurvatureByParam(aShape,theParam);
1090 }
1091
1092 //=============================================================================
1093 /*!
1094  *  CurveCurvatureByPoint
1095  */
1096 //=============================================================================
1097 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
1098                (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
1099 {
1100   //Set a not done flag
1101   GetOperations()->SetNotDone();
1102
1103   //Get the reference shape
1104   Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1105   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1106   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1107
1108   return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
1109 }
1110
1111
1112 //=============================================================================
1113 /*!
1114  *  MaxSurfaceCurvatureByParam
1115  */
1116 //=============================================================================
1117 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
1118                                                 (GEOM::GEOM_Object_ptr theSurf,
1119                                                  CORBA::Double theUParam,
1120                                                  CORBA::Double theVParam)
1121 {
1122   //Set a not done flag
1123   GetOperations()->SetNotDone();
1124
1125   //Get the reference shape
1126   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1127   if(aShape.IsNull()) return -1.0;
1128
1129   return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1130 }
1131
1132 //=============================================================================
1133 /*!
1134  *  MaxSurfaceCurvatureByPoint
1135  */
1136 //=============================================================================
1137 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
1138                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1139 {
1140   //Set a not done flag
1141   GetOperations()->SetNotDone();
1142
1143   //Get the reference shape
1144   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1145   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1146   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1147
1148   return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
1149 }
1150
1151 //=============================================================================
1152 /*!
1153  *  MinSurfaceCurvatureByParam
1154  */
1155 //=============================================================================
1156 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
1157                                                 (GEOM::GEOM_Object_ptr theSurf,
1158                                                  CORBA::Double theUParam,
1159                                                  CORBA::Double theVParam)
1160 {
1161   //Set a not done flag
1162   GetOperations()->SetNotDone();
1163
1164   //Get the reference shape
1165   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1166   if (aShape.IsNull()) return -1.0;
1167
1168   return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1169 }
1170
1171 //=============================================================================
1172 /*!
1173  *  MinSurfaceCurvatureByPoint
1174  */
1175 //=============================================================================
1176 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
1177                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1178 {
1179   //Set a not done flag
1180   GetOperations()->SetNotDone();
1181
1182   //Get the reference shape
1183   Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1184   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1185   if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
1186
1187   return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);
1188 }