1 // Copyright (C) 2007-2012 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 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
281 (GEOM::GEOM_Object_ptr theShape)
283 GEOM::GEOM_Object_var aGEOMObject;
285 //Set a not done flag
286 GetOperations()->SetNotDone();
288 //Get the reference shape
289 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
290 if (aShape.IsNull()) return aGEOMObject._retn();
292 // Make Box - bounding box of theShape
293 Handle(GEOM_Object) anObject = GetOperations()->GetBoundingBox(aShape);
294 if (!GetOperations()->IsDone() || anObject.IsNull())
295 return aGEOMObject._retn();
297 return GetObject(anObject);
300 //=============================================================================
304 //=============================================================================
305 void GEOM_IMeasureOperations_i::GetTolerance
306 (GEOM::GEOM_Object_ptr theShape,
307 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
308 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
309 CORBA::Double& VertMin, CORBA::Double& VertMax)
311 //Set a not done flag
312 GetOperations()->SetNotDone();
314 //Get the reference shape
315 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
316 if (aShape.IsNull()) return;
318 // Get shape parameters
319 GetOperations()->GetTolerance(aShape,
325 //=============================================================================
329 //=============================================================================
330 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
331 CORBA::String_out theDescription)
333 //Set a not done flag
334 GetOperations()->SetNotDone();
336 if (CORBA::is_nil(theShape))
338 theDescription = CORBA::string_dup("null");
342 //Get the reference shape
343 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
347 theDescription = CORBA::string_dup("null2");
351 // Get shape parameters
352 TCollection_AsciiString aDump;
353 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
355 theDescription = CORBA::string_dup("OK");
358 theDescription = CORBA::string_dup(aDump.ToCString());
362 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
363 CORBA::String_out theDescription)
365 //Set a not done flag
366 GetOperations()->SetNotDone();
368 if (CORBA::is_nil(theShape))
370 theDescription = CORBA::string_dup("null");
374 //Get the reference shape
375 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
379 theDescription = CORBA::string_dup("null2");
383 // Get shape parameters
384 TCollection_AsciiString aDump;
385 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
387 theDescription = CORBA::string_dup("OK");
390 theDescription = CORBA::string_dup(aDump.ToCString());
394 //=============================================================================
396 * CheckSelfIntersections
398 //=============================================================================
399 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
400 GEOM::ListOfLong_out theIntersections)
402 // Set a not done flag
403 GetOperations()->SetNotDone();
407 // Allocate the CORBA arrays
408 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
410 // Get the reference shape
411 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
413 if (!aShape.IsNull()) {
414 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
416 // Detect self-intersections
417 isGood = GetOperations()->CheckSelfIntersections(aShape, anIntegers);
419 int nbInts = anIntegers->Length();
421 anIntegersArray->length(nbInts);
423 for (int ii = 0; ii < nbInts; ii++) {
424 anIntegersArray[ii] = anIntegers->Value(ii + 1);
428 // Initialize out-parameters with local arrays
429 theIntersections = anIntegersArray._retn();
433 //=============================================================================
437 //=============================================================================
438 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
440 //Set a not done flag
441 GetOperations()->SetNotDone();
443 //Get the reference shape
444 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
445 if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
447 // Get shape parameters
448 TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
449 return CORBA::string_dup(aDescription.ToCString());
452 //=============================================================================
456 //=============================================================================
457 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
459 //Set a not done flag
460 GetOperations()->SetNotDone();
462 //Get the reference shape
463 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
464 if (aShape.IsNull()) return NULL;
466 // Get shape parameters
467 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
468 return CORBA::string_dup(aDescription.ToCString());
471 //=============================================================================
475 //=============================================================================
476 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
477 const GEOM::ListOfDouble& theCoords,
478 CORBA::Double tolerance)
480 //Set a not done flag
481 GetOperations()->SetNotDone();
483 unsigned int nb_points = theCoords.length()/3;
485 GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
486 aResults->length(nb_points);
488 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
490 std::vector<double> tmp(3*nb_points);
491 for (int i = 0; i < 3*nb_points; i++)
492 tmp[i] = theCoords[i];
493 std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
494 for (int i = 0; i < nb_points; i++)
495 aResults[i] = i < res.size() ? res[i] : false;
496 return aResults._retn();
499 //=============================================================================
503 //=============================================================================
504 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
505 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
506 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
507 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
509 //Set a not done flag
510 GetOperations()->SetNotDone();
512 //Get the reference shape
513 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
514 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
515 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
517 // Get shape parameters
518 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
521 //=============================================================================
525 //=============================================================================
526 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
527 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
528 GEOM::ListOfDouble_out theCoords)
530 //Set a not done flag
531 GetOperations()->SetNotDone();
533 // allocate the CORBA array
535 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
537 //Get the reference shape
538 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
539 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
541 if (!aShape1.IsNull() && !aShape2.IsNull()) {
542 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
543 // Get shape parameters
544 nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
545 int nbDbls = aDoubles->Length();
546 aDoublesArray->length(nbDbls);
547 for (int id = 0; id < nbDbls; id++) {
548 aDoublesArray[id] = aDoubles->Value(id + 1);
552 theCoords = aDoublesArray._retn();
556 //=============================================================================
560 //=============================================================================
561 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
562 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
565 //Set a not done flag
566 GetOperations()->SetNotDone();
568 //Get the reference shape
569 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
573 // Get shape parameters
574 GetOperations()->PointCoordinates( aShape, X, Y, Z );
577 //=============================================================================
581 //=============================================================================
582 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
583 GEOM::GEOM_Object_ptr theShape2)
585 //Set a not done flag
586 GetOperations()->SetNotDone();
588 //Get the reference shapes
589 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
590 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
591 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
594 return GetOperations()->GetAngle(aShape1, aShape2);
597 //=============================================================================
601 //=============================================================================
602 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
603 GEOM::GEOM_Object_ptr theShape2)
605 //Set a not done flag
606 GetOperations()->SetNotDone();
608 //Get the reference shapes
609 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
610 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
611 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
614 return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
618 //=============================================================================
620 * CurveCurvatureByParam
622 //=============================================================================
623 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
624 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
626 //Set a not done flag
627 GetOperations()->SetNotDone();
629 //Get the reference shape
630 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
631 if(aShape.IsNull()) return -1.0;
633 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
636 //=============================================================================
638 * CurveCurvatureByPoint
640 //=============================================================================
641 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
642 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
644 //Set a not done flag
645 GetOperations()->SetNotDone();
647 //Get the reference shape
648 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
649 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
650 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
652 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
656 //=============================================================================
658 * MaxSurfaceCurvatureByParam
660 //=============================================================================
661 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
662 (GEOM::GEOM_Object_ptr theSurf,
663 CORBA::Double theUParam,
664 CORBA::Double theVParam)
666 //Set a not done flag
667 GetOperations()->SetNotDone();
669 //Get the reference shape
670 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
671 if(aShape.IsNull()) return -1.0;
673 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
676 //=============================================================================
678 * MaxSurfaceCurvatureByPoint
680 //=============================================================================
681 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
682 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
684 //Set a not done flag
685 GetOperations()->SetNotDone();
687 //Get the reference shape
688 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
689 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
690 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
692 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
695 //=============================================================================
697 * MinSurfaceCurvatureByParam
699 //=============================================================================
700 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
701 (GEOM::GEOM_Object_ptr theSurf,
702 CORBA::Double theUParam,
703 CORBA::Double theVParam)
705 //Set a not done flag
706 GetOperations()->SetNotDone();
708 //Get the reference shape
709 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
710 if (aShape.IsNull()) return -1.0;
712 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
715 //=============================================================================
717 * MinSurfaceCurvatureByPoint
719 //=============================================================================
720 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
721 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
723 //Set a not done flag
724 GetOperations()->SetNotDone();
726 //Get the reference shape
727 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
728 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
729 if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
731 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);