Salome HOME
0020660: EDF 1238 GEOM: Missing equivalent of 2nd contructor of LCS in TUI
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include <Standard_Stream.hxx>
23
24 #include "GEOM_IMeasureOperations_i.hh"
25
26 #include "utilities.h"
27 #include "OpUtil.hxx"
28
29 #include "GEOM_Engine.hxx"
30 #include "GEOM_Object.hxx"
31
32 //=============================================================================
33 /*!
34  *   constructor:
35  */
36 //=============================================================================
37 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
38                                                       GEOM::GEOM_Gen_ptr theEngine,
39                                                       ::GEOMImpl_IMeasureOperations* theImpl)
40 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
41 {
42   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
43 }
44
45 //=============================================================================
46 /*!
47  *  destructor
48  */
49 //=============================================================================
50 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
51 {
52   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
53 }
54
55 //=============================================================================
56 /*!
57  *  KindOfShape
58  */
59 //=============================================================================
60 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
61                                    (GEOM::GEOM_Object_ptr  theShape,
62                                     GEOM::ListOfLong_out   theIntegers,
63                                     GEOM::ListOfDouble_out theDoubles)
64 {
65   GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
66
67   // allocate the CORBA arrays
68   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
69   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
70
71   //Get the reference shape
72   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
73
74   if (!aShape.IsNull()) {
75     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
76     Handle(TColStd_HSequenceOfReal)    aDoubles   = new TColStd_HSequenceOfReal;
77
78     // Detect kind of shape and parameters
79     aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
80
81     int nbInts = anIntegers->Length();
82     int nbDbls = aDoubles->Length();
83
84     anIntegersArray->length(nbInts);
85     aDoublesArray->length(nbDbls);
86
87     for (int ii = 0; ii < nbInts; ii++) {
88       anIntegersArray[ii] = anIntegers->Value(ii + 1);
89     }
90     for (int id = 0; id < nbDbls; id++) {
91       aDoublesArray[id] = aDoubles->Value(id + 1);
92     }
93   }
94
95   // initialize out-parameters with local arrays
96   theIntegers = anIntegersArray._retn();
97   theDoubles  = aDoublesArray._retn();
98   return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
99 }
100
101 //=============================================================================
102 /*!
103  *  GetPosition
104  */
105 //=============================================================================
106 void GEOM_IMeasureOperations_i::GetPosition
107                  (GEOM::GEOM_Object_ptr theShape,
108                   CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
109                   CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
110                   CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
111 {
112   //Set a not done flag
113   GetOperations()->SetNotDone();
114
115   //Set default values: global CS
116   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
117   Zz = Xx = 1.;
118
119   //Get the reference shape
120   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
121   if (aShape.IsNull()) return;
122
123   // Get shape parameters
124   GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
125 }
126
127 //=============================================================================
128 /*!
129  *  GetCentreOfMass
130  */
131 //=============================================================================
132 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
133                                               (GEOM::GEOM_Object_ptr theShape)
134 {
135   GEOM::GEOM_Object_var aGEOMObject;
136
137   //Set a not done flag
138   GetOperations()->SetNotDone();
139
140   //Get the reference shape
141   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
142   if (aShape.IsNull()) return aGEOMObject._retn();
143
144   // Make Point - centre of mass of theShape
145   Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
146   if (!GetOperations()->IsDone() || anObject.IsNull())
147     return aGEOMObject._retn();
148
149   return GetObject(anObject);
150 }
151
152 //=============================================================================
153 /*!
154  *  GetNormal
155  */
156 //=============================================================================
157 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
158                                        (GEOM::GEOM_Object_ptr theFace,
159                                         GEOM::GEOM_Object_ptr theOptionalPoint)
160 {
161   GEOM::GEOM_Object_var aGEOMObject;
162
163   //Set a not done flag
164   GetOperations()->SetNotDone();
165
166   //Get the reference shape
167   Handle(GEOM_Object) aFace = GetObjectImpl(theFace);
168   if (aFace.IsNull()) return aGEOMObject._retn();
169
170   // Get the OptionalPoint (can be not defined)
171   Handle(GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
172
173   // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
174   Handle(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
175   if (!GetOperations()->IsDone() || anObject.IsNull())
176     return aGEOMObject._retn();
177
178   return GetObject(anObject);
179 }
180
181 //=============================================================================
182 /*!
183  *  GetBasicProperties
184  */
185 //=============================================================================
186 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
187                                                     CORBA::Double& theLength,
188                                                     CORBA::Double& theSurfArea,
189                                                     CORBA::Double& theVolume)
190 {
191   //Set a not done flag
192   GetOperations()->SetNotDone();
193
194   //Get the reference shape
195   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
196   if (aShape.IsNull()) return;
197
198   // Get shape parameters
199   GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
200 }
201
202 //=============================================================================
203 /*!
204  *  GetInertia
205  */
206 //=============================================================================
207 void GEOM_IMeasureOperations_i::GetInertia
208   (GEOM::GEOM_Object_ptr theShape,
209    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
210    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
211    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
212    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
213 {
214   //Set a not done flag
215   GetOperations()->SetNotDone();
216
217   //Get the reference shape
218   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
219   if (aShape.IsNull()) return;
220
221   // Get shape parameters
222   GetOperations()->GetInertia(aShape,
223                               I11, I12, I13,
224                               I21, I22, I23,
225                               I31, I32, I33,
226                               Ix , Iy , Iz);
227 }
228
229 //=============================================================================
230 /*!
231  *  GetBoundingBox
232  */
233 //=============================================================================
234 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
235                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
236                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
237                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
238 {
239   //Set a not done flag
240   GetOperations()->SetNotDone();
241
242   //Get the reference shape
243   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
244   if (aShape.IsNull()) return;
245
246   // Get shape parameters
247   GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
248 }
249
250 //=============================================================================
251 /*!
252  *  GetTolerance
253  */
254 //=============================================================================
255 void GEOM_IMeasureOperations_i::GetTolerance
256                                 (GEOM::GEOM_Object_ptr theShape,
257                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
258                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
259                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
260 {
261   //Set a not done flag
262   GetOperations()->SetNotDone();
263
264   //Get the reference shape
265   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
266   if (aShape.IsNull()) return;
267
268   // Get shape parameters
269   GetOperations()->GetTolerance(aShape,
270                                 FaceMin, FaceMax,
271                                 EdgeMin, EdgeMax,
272                                 VertMin, VertMax);
273 }
274
275 //=============================================================================
276 /*!
277  *  CheckShape
278  */
279 //=============================================================================
280 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
281                                                       CORBA::String_out     theDescription)
282 {
283   //Set a not done flag
284   GetOperations()->SetNotDone();
285
286   if (CORBA::is_nil(theShape))
287   {
288     theDescription = CORBA::string_dup("null");
289     return 0;
290   }
291
292   //Get the reference shape
293   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
294
295   if (aShape.IsNull())
296   {
297     theDescription = CORBA::string_dup("null2");
298     return 0;
299   }
300
301   // Get shape parameters
302   TCollection_AsciiString aDump;
303   if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
304   {
305     theDescription = CORBA::string_dup("OK");
306     return 1;
307   }
308   theDescription = CORBA::string_dup(aDump.ToCString());
309   return 0;
310 }
311
312 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
313                                                                   CORBA::String_out     theDescription)
314 {
315   //Set a not done flag
316   GetOperations()->SetNotDone();
317
318   if (CORBA::is_nil(theShape))
319   {
320     theDescription = CORBA::string_dup("null");
321     return 0;
322   }
323
324   //Get the reference shape
325   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
326
327   if (aShape.IsNull())
328   {
329     theDescription = CORBA::string_dup("null2");
330     return 0;
331   }
332
333   // Get shape parameters
334   TCollection_AsciiString aDump;
335   if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
336   {
337     theDescription = CORBA::string_dup("OK");
338     return 1;
339   }
340   theDescription = CORBA::string_dup(aDump.ToCString());
341   return 0;
342 }
343
344 //=============================================================================
345 /*!
346  *  WhatIs
347  */
348 //=============================================================================
349 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
350 {
351   //Set a not done flag
352   GetOperations()->SetNotDone();
353
354   //Get the reference shape
355   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
356   if (aShape.IsNull()) return NULL;
357
358   // Get shape parameters
359   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
360   return CORBA::string_dup(aDescription.ToCString());
361 }
362
363 //=============================================================================
364 /*!
365  *  GetMinDistance
366  */
367 //=============================================================================
368 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
369   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
370    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
371    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
372 {
373   //Set a not done flag
374   GetOperations()->SetNotDone();
375
376   //Get the reference shape
377   Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
378   Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
379   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
380
381   // Get shape parameters
382   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
383 }
384
385 //=============================================================================
386 /*!
387  *  PointCoordinates
388  */
389 //=============================================================================
390 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
391                                                   CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
392
393 {
394   //Set a not done flag
395   GetOperations()->SetNotDone();
396
397   //Get the reference shape
398   Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
399   if (aShape.IsNull())
400     return;
401
402   // Get shape parameters
403   GetOperations()->PointCoordinates( aShape, X, Y, Z );
404 }
405
406 //=============================================================================
407 /*!
408  *  GetAngle
409  */
410 //=============================================================================
411 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
412                                                    GEOM::GEOM_Object_ptr theShape2)
413 {
414   //Set a not done flag
415   GetOperations()->SetNotDone();
416
417   //Get the reference shapes
418   Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
419   Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
420   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
421
422   // Get the angle
423   return GetOperations()->GetAngle(aShape1, aShape2);
424 }
425
426
427 //=============================================================================
428 /*!
429  *  CurveCurvatureByParam
430  */
431 //=============================================================================
432 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
433                        (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
434 {
435   //Set a not done flag
436   GetOperations()->SetNotDone();
437
438   //Get the reference shape
439   Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
440   if(aShape.IsNull()) return -1.0;
441
442   return GetOperations()->CurveCurvatureByParam(aShape,theParam);
443 }
444
445 //=============================================================================
446 /*!
447  *  CurveCurvatureByPoint
448  */
449 //=============================================================================
450 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
451                (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
452 {
453   //Set a not done flag
454   GetOperations()->SetNotDone();
455
456   //Get the reference shape
457   Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
458   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
459   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
460
461   return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
462 }
463
464
465 //=============================================================================
466 /*!
467  *  MaxSurfaceCurvatureByParam
468  */
469 //=============================================================================
470 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
471                                                 (GEOM::GEOM_Object_ptr theSurf,
472                                                  CORBA::Double theUParam,
473                                                  CORBA::Double theVParam)
474 {
475   //Set a not done flag
476   GetOperations()->SetNotDone();
477
478   //Get the reference shape
479   Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
480   if(aShape.IsNull()) return -1.0;
481
482   return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
483 }
484
485 //=============================================================================
486 /*!
487  *  MaxSurfaceCurvatureByPoint
488  */
489 //=============================================================================
490 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
491                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
492 {
493   //Set a not done flag
494   GetOperations()->SetNotDone();
495
496   //Get the reference shape
497   Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
498   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
499   if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
500
501   return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
502 }
503
504 //=============================================================================
505 /*!
506  *  MinSurfaceCurvatureByParam
507  */
508 //=============================================================================
509 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
510                                                 (GEOM::GEOM_Object_ptr theSurf,
511                                                  CORBA::Double theUParam,
512                                                  CORBA::Double theVParam)
513 {
514   //Set a not done flag
515   GetOperations()->SetNotDone();
516
517   //Get the reference shape
518   Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
519   if (aShape.IsNull()) return -1.0;
520
521   return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
522 }
523
524 //=============================================================================
525 /*!
526  *  MinSurfaceCurvatureByPoint
527  */
528 //=============================================================================
529 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
530                 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
531 {
532   //Set a not done flag
533   GetOperations()->SetNotDone();
534
535   //Get the reference shape
536   Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
537   Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
538   if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
539
540   return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);
541 }