1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include "GEOM_IMeasureOperations_i.hh"
26 #include "utilities.h"
29 #include "GEOM_Engine.hxx"
30 #include "GEOM_Object.hxx"
32 //=============================================================================
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)
42 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
45 //=============================================================================
49 //=============================================================================
50 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
52 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
55 //=============================================================================
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)
65 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
67 // allocate the CORBA arrays
68 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
69 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
71 //Get the reference shape
72 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
74 if (!aShape.IsNull()) {
75 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
76 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
78 // Detect kind of shape and parameters
79 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
81 int nbInts = anIntegers->Length();
82 int nbDbls = aDoubles->Length();
84 anIntegersArray->length(nbInts);
85 aDoublesArray->length(nbDbls);
87 for (int ii = 0; ii < nbInts; ii++) {
88 anIntegersArray[ii] = anIntegers->Value(ii + 1);
90 for (int id = 0; id < nbDbls; id++) {
91 aDoublesArray[id] = aDoubles->Value(id + 1);
95 // initialize out-parameters with local arrays
96 theIntegers = anIntegersArray._retn();
97 theDoubles = aDoublesArray._retn();
98 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
101 //=============================================================================
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)
112 //Set a not done flag
113 GetOperations()->SetNotDone();
115 //Set default values: global CS
116 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
119 //Get the reference shape
120 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
121 if (aShape.IsNull()) return;
123 // Get shape parameters
124 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
127 //=============================================================================
131 //=============================================================================
132 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
133 (GEOM::GEOM_Object_ptr theShape)
135 GEOM::GEOM_Object_var aGEOMObject;
137 //Set a not done flag
138 GetOperations()->SetNotDone();
140 //Get the reference shape
141 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
142 if (aShape.IsNull()) return aGEOMObject._retn();
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();
149 return GetObject(anObject);
152 //=============================================================================
156 //=============================================================================
157 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex
158 (GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex)
160 GEOM::GEOM_Object_var aGEOMObject;
162 //Set a not done flag
163 GetOperations()->SetNotDone();
165 //Get the reference shape
166 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
167 if ( aShape.IsNull() ) return aGEOMObject._retn();
169 // Get vertex by index
170 Handle(GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex);
171 if (!GetOperations()->IsDone() || anObject.IsNull())
172 return aGEOMObject._retn();
174 return GetObject(anObject);
177 //=============================================================================
181 //=============================================================================
182 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
183 (GEOM::GEOM_Object_ptr theFace,
184 GEOM::GEOM_Object_ptr theOptionalPoint)
186 GEOM::GEOM_Object_var aGEOMObject;
188 //Set a not done flag
189 GetOperations()->SetNotDone();
191 //Get the reference shape
192 Handle(GEOM_Object) aFace = GetObjectImpl(theFace);
193 if (aFace.IsNull()) return aGEOMObject._retn();
195 // Get the OptionalPoint (can be not defined)
196 Handle(GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
198 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
199 Handle(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
200 if (!GetOperations()->IsDone() || anObject.IsNull())
201 return aGEOMObject._retn();
203 return GetObject(anObject);
206 //=============================================================================
210 //=============================================================================
211 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
212 CORBA::Double& theLength,
213 CORBA::Double& theSurfArea,
214 CORBA::Double& theVolume)
216 //Set a not done flag
217 GetOperations()->SetNotDone();
219 //Get the reference shape
220 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
221 if (aShape.IsNull()) return;
223 // Get shape parameters
224 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
227 //=============================================================================
231 //=============================================================================
232 void GEOM_IMeasureOperations_i::GetInertia
233 (GEOM::GEOM_Object_ptr theShape,
234 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
235 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
236 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
237 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
239 //Set a not done flag
240 GetOperations()->SetNotDone();
242 //Get the reference shape
243 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
244 if (aShape.IsNull()) return;
246 // Get shape parameters
247 GetOperations()->GetInertia(aShape,
254 //=============================================================================
258 //=============================================================================
259 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
260 CORBA::Double& Xmin, CORBA::Double& Xmax,
261 CORBA::Double& Ymin, CORBA::Double& Ymax,
262 CORBA::Double& Zmin, CORBA::Double& Zmax)
264 //Set a not done flag
265 GetOperations()->SetNotDone();
267 //Get the reference shape
268 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
269 if (aShape.IsNull()) return;
271 // Get shape parameters
272 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
275 //=============================================================================
279 //=============================================================================
280 void GEOM_IMeasureOperations_i::GetTolerance
281 (GEOM::GEOM_Object_ptr theShape,
282 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
283 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
284 CORBA::Double& VertMin, CORBA::Double& VertMax)
286 //Set a not done flag
287 GetOperations()->SetNotDone();
289 //Get the reference shape
290 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
291 if (aShape.IsNull()) return;
293 // Get shape parameters
294 GetOperations()->GetTolerance(aShape,
300 //=============================================================================
304 //=============================================================================
305 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
306 CORBA::String_out theDescription)
308 //Set a not done flag
309 GetOperations()->SetNotDone();
311 if (CORBA::is_nil(theShape))
313 theDescription = CORBA::string_dup("null");
317 //Get the reference shape
318 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
322 theDescription = CORBA::string_dup("null2");
326 // Get shape parameters
327 TCollection_AsciiString aDump;
328 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
330 theDescription = CORBA::string_dup("OK");
333 theDescription = CORBA::string_dup(aDump.ToCString());
337 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
338 CORBA::String_out theDescription)
340 //Set a not done flag
341 GetOperations()->SetNotDone();
343 if (CORBA::is_nil(theShape))
345 theDescription = CORBA::string_dup("null");
349 //Get the reference shape
350 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
354 theDescription = CORBA::string_dup("null2");
358 // Get shape parameters
359 TCollection_AsciiString aDump;
360 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
362 theDescription = CORBA::string_dup("OK");
365 theDescription = CORBA::string_dup(aDump.ToCString());
369 //=============================================================================
373 //=============================================================================
374 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
376 //Set a not done flag
377 GetOperations()->SetNotDone();
379 //Get the reference shape
380 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
381 if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
383 // Get shape parameters
384 TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
385 return CORBA::string_dup(aDescription.ToCString());
388 //=============================================================================
392 //=============================================================================
393 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
395 //Set a not done flag
396 GetOperations()->SetNotDone();
398 //Get the reference shape
399 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
400 if (aShape.IsNull()) return NULL;
402 // Get shape parameters
403 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
404 return CORBA::string_dup(aDescription.ToCString());
407 //=============================================================================
411 //=============================================================================
412 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
413 const GEOM::ListOfDouble& theCoords,
414 CORBA::Double tolerance)
416 //Set a not done flag
417 GetOperations()->SetNotDone();
419 unsigned int nb_points = theCoords.length()/3;
421 GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
422 aResults->length(nb_points);
424 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
426 std::vector<double> tmp(3*nb_points);
427 for (int i = 0; i < 3*nb_points; i++)
428 tmp[i] = theCoords[i];
429 std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
430 for (int i = 0; i < nb_points; i++)
431 aResults[i] = i < res.size() ? res[i] : false;
432 return aResults._retn();
435 //=============================================================================
439 //=============================================================================
440 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
441 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
442 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
443 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
445 //Set a not done flag
446 GetOperations()->SetNotDone();
448 //Get the reference shape
449 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
450 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
451 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
453 // Get shape parameters
454 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
457 //=============================================================================
461 //=============================================================================
462 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
463 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
466 //Set a not done flag
467 GetOperations()->SetNotDone();
469 //Get the reference shape
470 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
474 // Get shape parameters
475 GetOperations()->PointCoordinates( aShape, X, Y, Z );
478 //=============================================================================
482 //=============================================================================
483 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
484 GEOM::GEOM_Object_ptr theShape2)
486 //Set a not done flag
487 GetOperations()->SetNotDone();
489 //Get the reference shapes
490 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
491 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
492 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
495 return GetOperations()->GetAngle(aShape1, aShape2);
498 //=============================================================================
502 //=============================================================================
503 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
504 GEOM::GEOM_Object_ptr theShape2)
506 //Set a not done flag
507 GetOperations()->SetNotDone();
509 //Get the reference shapes
510 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
511 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
512 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
515 return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
519 //=============================================================================
521 * CurveCurvatureByParam
523 //=============================================================================
524 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
525 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
527 //Set a not done flag
528 GetOperations()->SetNotDone();
530 //Get the reference shape
531 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
532 if(aShape.IsNull()) return -1.0;
534 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
537 //=============================================================================
539 * CurveCurvatureByPoint
541 //=============================================================================
542 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
543 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
545 //Set a not done flag
546 GetOperations()->SetNotDone();
548 //Get the reference shape
549 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
550 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
551 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
553 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
557 //=============================================================================
559 * MaxSurfaceCurvatureByParam
561 //=============================================================================
562 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
563 (GEOM::GEOM_Object_ptr theSurf,
564 CORBA::Double theUParam,
565 CORBA::Double theVParam)
567 //Set a not done flag
568 GetOperations()->SetNotDone();
570 //Get the reference shape
571 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
572 if(aShape.IsNull()) return -1.0;
574 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
577 //=============================================================================
579 * MaxSurfaceCurvatureByPoint
581 //=============================================================================
582 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
583 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
585 //Set a not done flag
586 GetOperations()->SetNotDone();
588 //Get the reference shape
589 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
590 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
591 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
593 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
596 //=============================================================================
598 * MinSurfaceCurvatureByParam
600 //=============================================================================
601 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
602 (GEOM::GEOM_Object_ptr theSurf,
603 CORBA::Double theUParam,
604 CORBA::Double theVParam)
606 //Set a not done flag
607 GetOperations()->SetNotDone();
609 //Get the reference shape
610 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
611 if (aShape.IsNull()) return -1.0;
613 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
616 //=============================================================================
618 * MinSurfaceCurvatureByPoint
620 //=============================================================================
621 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
622 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
624 //Set a not done flag
625 GetOperations()->SetNotDone();
627 //Get the reference shape
628 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
629 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
630 if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
632 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);