1 // Copyright (C) 2007-2013 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
23 #include <Standard_Stream.hxx>
25 #include "GEOM_IMeasureOperations_i.hh"
27 #include "utilities.h"
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
33 //=============================================================================
37 //=============================================================================
38 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
39 GEOM::GEOM_Gen_ptr theEngine,
40 ::GEOMImpl_IMeasureOperations* theImpl)
41 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
46 //=============================================================================
50 //=============================================================================
51 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
53 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
56 //=============================================================================
60 //=============================================================================
61 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
62 (GEOM::GEOM_Object_ptr theShape,
63 GEOM::ListOfLong_out theIntegers,
64 GEOM::ListOfDouble_out theDoubles)
66 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
68 // allocate the CORBA arrays
69 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
70 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
72 //Get the reference shape
73 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
75 if (!aShape.IsNull()) {
76 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
77 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
79 // Detect kind of shape and parameters
80 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
82 int nbInts = anIntegers->Length();
83 int nbDbls = aDoubles->Length();
85 anIntegersArray->length(nbInts);
86 aDoublesArray->length(nbDbls);
88 for (int ii = 0; ii < nbInts; ii++) {
89 anIntegersArray[ii] = anIntegers->Value(ii + 1);
91 for (int id = 0; id < nbDbls; id++) {
92 aDoublesArray[id] = aDoubles->Value(id + 1);
96 // initialize out-parameters with local arrays
97 theIntegers = anIntegersArray._retn();
98 theDoubles = aDoublesArray._retn();
99 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
102 //=============================================================================
106 //=============================================================================
107 void GEOM_IMeasureOperations_i::GetPosition
108 (GEOM::GEOM_Object_ptr theShape,
109 CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
110 CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
111 CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
113 //Set a not done flag
114 GetOperations()->SetNotDone();
116 //Set default values: global CS
117 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
120 //Get the reference shape
121 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
122 if (aShape.IsNull()) return;
124 // Get shape parameters
125 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
128 //=============================================================================
132 //=============================================================================
133 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
134 (GEOM::GEOM_Object_ptr theShape)
136 GEOM::GEOM_Object_var aGEOMObject;
138 //Set a not done flag
139 GetOperations()->SetNotDone();
141 //Get the reference shape
142 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
143 if (aShape.IsNull()) return aGEOMObject._retn();
145 // Make Point - centre of mass of theShape
146 Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
147 if (!GetOperations()->IsDone() || anObject.IsNull())
148 return aGEOMObject._retn();
150 return GetObject(anObject);
153 //=============================================================================
157 //=============================================================================
158 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex
159 (GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex)
161 GEOM::GEOM_Object_var aGEOMObject;
163 //Set a not done flag
164 GetOperations()->SetNotDone();
166 //Get the reference shape
167 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
168 if ( aShape.IsNull() ) return aGEOMObject._retn();
170 // Get vertex by index
171 Handle(GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex);
172 if (!GetOperations()->IsDone() || anObject.IsNull())
173 return aGEOMObject._retn();
175 return GetObject(anObject);
178 //=============================================================================
182 //=============================================================================
183 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
184 (GEOM::GEOM_Object_ptr theFace,
185 GEOM::GEOM_Object_ptr theOptionalPoint)
187 GEOM::GEOM_Object_var aGEOMObject;
189 //Set a not done flag
190 GetOperations()->SetNotDone();
192 //Get the reference shape
193 Handle(GEOM_Object) aFace = GetObjectImpl(theFace);
194 if (aFace.IsNull()) return aGEOMObject._retn();
196 // Get the OptionalPoint (can be not defined)
197 Handle(GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
199 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
200 Handle(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
201 if (!GetOperations()->IsDone() || anObject.IsNull())
202 return aGEOMObject._retn();
204 return GetObject(anObject);
207 //=============================================================================
211 //=============================================================================
212 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
213 CORBA::Double& theLength,
214 CORBA::Double& theSurfArea,
215 CORBA::Double& theVolume)
217 //Set a not done flag
218 GetOperations()->SetNotDone();
220 //Get the reference shape
221 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
222 if (aShape.IsNull()) return;
224 // Get shape parameters
225 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
228 //=============================================================================
232 //=============================================================================
233 void GEOM_IMeasureOperations_i::GetInertia
234 (GEOM::GEOM_Object_ptr theShape,
235 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
236 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
237 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
238 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
240 //Set a not done flag
241 GetOperations()->SetNotDone();
243 //Get the reference shape
244 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
245 if (aShape.IsNull()) return;
247 // Get shape parameters
248 GetOperations()->GetInertia(aShape,
255 //=============================================================================
259 //=============================================================================
260 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
261 CORBA::Double& Xmin, CORBA::Double& Xmax,
262 CORBA::Double& Ymin, CORBA::Double& Ymax,
263 CORBA::Double& Zmin, CORBA::Double& Zmax)
265 //Set a not done flag
266 GetOperations()->SetNotDone();
268 //Get the reference shape
269 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
270 if (aShape.IsNull()) return;
272 // Get shape parameters
273 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
276 //=============================================================================
280 //=============================================================================
281 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
282 (GEOM::GEOM_Object_ptr theShape)
284 GEOM::GEOM_Object_var aGEOMObject;
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 aGEOMObject._retn();
293 // Make Box - bounding box of theShape
294 Handle(GEOM_Object) anObject = GetOperations()->GetBoundingBox(aShape);
295 if (!GetOperations()->IsDone() || anObject.IsNull())
296 return aGEOMObject._retn();
298 return GetObject(anObject);
301 //=============================================================================
305 //=============================================================================
306 void GEOM_IMeasureOperations_i::GetTolerance
307 (GEOM::GEOM_Object_ptr theShape,
308 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
309 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
310 CORBA::Double& VertMin, CORBA::Double& VertMax)
312 //Set a not done flag
313 GetOperations()->SetNotDone();
315 //Get the reference shape
316 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
317 if (aShape.IsNull()) return;
319 // Get shape parameters
320 GetOperations()->GetTolerance(aShape,
326 //=============================================================================
330 //=============================================================================
331 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
332 CORBA::String_out theDescription)
334 //Set a not done flag
335 GetOperations()->SetNotDone();
337 if (CORBA::is_nil(theShape))
339 theDescription = CORBA::string_dup("null");
343 //Get the reference shape
344 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
348 theDescription = CORBA::string_dup("null2");
352 // Get shape parameters
353 TCollection_AsciiString aDump;
354 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
356 theDescription = CORBA::string_dup("OK");
359 theDescription = CORBA::string_dup(aDump.ToCString());
363 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
364 CORBA::String_out theDescription)
366 //Set a not done flag
367 GetOperations()->SetNotDone();
369 if (CORBA::is_nil(theShape))
371 theDescription = CORBA::string_dup("null");
375 //Get the reference shape
376 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
380 theDescription = CORBA::string_dup("null2");
384 // Get shape parameters
385 TCollection_AsciiString aDump;
386 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
388 theDescription = CORBA::string_dup("OK");
391 theDescription = CORBA::string_dup(aDump.ToCString());
395 //=============================================================================
397 * CheckSelfIntersections
399 //=============================================================================
400 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
401 GEOM::ListOfLong_out theIntersections)
403 // Set a not done flag
404 GetOperations()->SetNotDone();
408 // Allocate the CORBA arrays
409 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
411 // Get the reference shape
412 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
414 if (!aShape.IsNull()) {
415 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
417 // Detect self-intersections
418 isGood = GetOperations()->CheckSelfIntersections(aShape, anIntegers);
420 int nbInts = anIntegers->Length();
422 anIntegersArray->length(nbInts);
424 for (int ii = 0; ii < nbInts; ii++) {
425 anIntegersArray[ii] = anIntegers->Value(ii + 1);
429 // Initialize out-parameters with local arrays
430 theIntersections = anIntegersArray._retn();
434 //=============================================================================
438 //=============================================================================
439 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
441 //Set a not done flag
442 GetOperations()->SetNotDone();
444 //Get the reference shape
445 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
446 if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
448 // Get shape parameters
449 TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
450 return CORBA::string_dup(aDescription.ToCString());
453 //=============================================================================
457 //=============================================================================
458 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
460 //Set a not done flag
461 GetOperations()->SetNotDone();
463 //Get the reference shape
464 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
465 if (aShape.IsNull()) return NULL;
467 // Get shape parameters
468 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
469 return CORBA::string_dup(aDescription.ToCString());
472 //=============================================================================
476 //=============================================================================
477 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
478 const GEOM::ListOfDouble& theCoords,
479 CORBA::Double tolerance)
481 //Set a not done flag
482 GetOperations()->SetNotDone();
484 unsigned int nb_points = theCoords.length()/3;
486 GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
487 aResults->length(nb_points);
489 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
491 std::vector<double> tmp(3*nb_points);
492 for (int i = 0; i < 3*nb_points; i++)
493 tmp[i] = theCoords[i];
494 std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
495 for (int i = 0; i < nb_points; i++)
496 aResults[i] = i < res.size() ? res[i] : false;
497 return aResults._retn();
500 //=============================================================================
504 //=============================================================================
505 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
506 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
507 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
508 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
510 //Set a not done flag
511 GetOperations()->SetNotDone();
513 //Get the reference shape
514 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
515 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
516 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
518 // Get shape parameters
519 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
522 //=============================================================================
526 //=============================================================================
527 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
528 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
529 GEOM::ListOfDouble_out theCoords)
531 //Set a not done flag
532 GetOperations()->SetNotDone();
534 // allocate the CORBA array
536 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
538 //Get the reference shape
539 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
540 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
542 if (!aShape1.IsNull() && !aShape2.IsNull()) {
543 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
544 // Get shape parameters
545 nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
546 int nbDbls = aDoubles->Length();
547 aDoublesArray->length(nbDbls);
548 for (int id = 0; id < nbDbls; id++) {
549 aDoublesArray[id] = aDoubles->Value(id + 1);
553 theCoords = aDoublesArray._retn();
557 //=============================================================================
561 //=============================================================================
562 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
563 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
566 //Set a not done flag
567 GetOperations()->SetNotDone();
569 //Get the reference shape
570 Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
574 // Get shape parameters
575 GetOperations()->PointCoordinates( aShape, X, Y, Z );
578 //=============================================================================
582 //=============================================================================
583 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
584 GEOM::GEOM_Object_ptr theShape2)
586 //Set a not done flag
587 GetOperations()->SetNotDone();
589 //Get the reference shapes
590 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
591 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
592 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
595 return GetOperations()->GetAngle(aShape1, aShape2);
598 //=============================================================================
602 //=============================================================================
603 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
604 GEOM::GEOM_Object_ptr theShape2)
606 //Set a not done flag
607 GetOperations()->SetNotDone();
609 //Get the reference shapes
610 Handle(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
611 Handle(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
612 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
615 return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
619 //=============================================================================
621 * CurveCurvatureByParam
623 //=============================================================================
624 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
625 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
627 //Set a not done flag
628 GetOperations()->SetNotDone();
630 //Get the reference shape
631 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
632 if(aShape.IsNull()) return -1.0;
634 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
637 //=============================================================================
639 * CurveCurvatureByPoint
641 //=============================================================================
642 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
643 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
645 //Set a not done flag
646 GetOperations()->SetNotDone();
648 //Get the reference shape
649 Handle(GEOM_Object) aShape = GetObjectImpl(theCurve);
650 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
651 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
653 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
657 //=============================================================================
659 * MaxSurfaceCurvatureByParam
661 //=============================================================================
662 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
663 (GEOM::GEOM_Object_ptr theSurf,
664 CORBA::Double theUParam,
665 CORBA::Double theVParam)
667 //Set a not done flag
668 GetOperations()->SetNotDone();
670 //Get the reference shape
671 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
672 if(aShape.IsNull()) return -1.0;
674 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
677 //=============================================================================
679 * MaxSurfaceCurvatureByPoint
681 //=============================================================================
682 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
683 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
685 //Set a not done flag
686 GetOperations()->SetNotDone();
688 //Get the reference shape
689 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
690 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
691 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
693 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
696 //=============================================================================
698 * MinSurfaceCurvatureByParam
700 //=============================================================================
701 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
702 (GEOM::GEOM_Object_ptr theSurf,
703 CORBA::Double theUParam,
704 CORBA::Double theVParam)
706 //Set a not done flag
707 GetOperations()->SetNotDone();
709 //Get the reference shape
710 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
711 if (aShape.IsNull()) return -1.0;
713 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
716 //=============================================================================
718 * MinSurfaceCurvatureByPoint
720 //=============================================================================
721 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
722 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
724 //Set a not done flag
725 GetOperations()->SetNotDone();
727 //Get the reference shape
728 Handle(GEOM_Object) aShape = GetObjectImpl(theSurf);
729 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
730 if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
732 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);