1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include "GEOM_IMeasureOperations_i.hh"
25 #include "utilities.h"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 //=============================================================================
35 //=============================================================================
36 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
37 GEOM::GEOM_Gen_ptr theEngine,
38 ::GEOMImpl_IMeasureOperations* theImpl)
39 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
41 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
44 //=============================================================================
48 //=============================================================================
49 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
51 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
54 //=============================================================================
58 //=============================================================================
59 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
60 (GEOM::GEOM_Object_ptr theShape,
61 GEOM::ListOfLong_out theIntegers,
62 GEOM::ListOfDouble_out theDoubles)
64 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
66 // allocate the CORBA arrays
67 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
68 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
70 //Get the reference shape
71 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
72 (theShape->GetStudyID(), theShape->GetEntry());
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 if (theShape == NULL) return;
121 //Get the reference shape
122 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
123 (theShape->GetStudyID(), theShape->GetEntry());
125 if (aShape.IsNull()) return;
127 // Get shape parameters
128 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
131 //=============================================================================
135 //=============================================================================
136 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
137 (GEOM::GEOM_Object_ptr theShape)
139 GEOM::GEOM_Object_var aGEOMObject;
141 //Set a not done flag
142 GetOperations()->SetNotDone();
144 if (CORBA::is_nil(theShape)) return aGEOMObject._retn();
146 //Get the reference shape
147 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
148 (theShape->GetStudyID(), theShape->GetEntry());
150 if (aShape.IsNull()) return aGEOMObject._retn();
152 // Make Point - centre of mass of theShape
153 Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
154 if (!GetOperations()->IsDone() || anObject.IsNull())
155 return aGEOMObject._retn();
157 return GetObject(anObject);
160 //=============================================================================
164 //=============================================================================
165 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
166 (GEOM::GEOM_Object_ptr theFace,
167 GEOM::GEOM_Object_ptr theOptionalPoint)
169 GEOM::GEOM_Object_var aGEOMObject;
171 //Set a not done flag
172 GetOperations()->SetNotDone();
174 if (CORBA::is_nil(theFace)) return aGEOMObject._retn();
176 //Get the reference shape
177 Handle(GEOM_Object) aFace = GetOperations()->GetEngine()->GetObject
178 (theFace->GetStudyID(), theFace->GetEntry());
180 if (aFace.IsNull()) return aGEOMObject._retn();
182 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
183 Handle(GEOM_Object) anOptionalPoint;
184 if (!CORBA::is_nil(theOptionalPoint)) {
185 anOptionalPoint = GetOperations()->GetEngine()->GetObject
186 (theOptionalPoint->GetStudyID(), theOptionalPoint->GetEntry());
188 Handle(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
189 if (!GetOperations()->IsDone() || anObject.IsNull())
190 return aGEOMObject._retn();
192 return GetObject(anObject);
195 //=============================================================================
199 //=============================================================================
200 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
201 CORBA::Double& theLength,
202 CORBA::Double& theSurfArea,
203 CORBA::Double& theVolume)
205 //Set a not done flag
206 GetOperations()->SetNotDone();
208 if (theShape == NULL) return;
210 //Get the reference shape
211 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
212 (theShape->GetStudyID(), theShape->GetEntry());
214 if (aShape.IsNull()) return;
216 // Get shape parameters
217 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
220 //=============================================================================
224 //=============================================================================
225 void GEOM_IMeasureOperations_i::GetInertia
226 (GEOM::GEOM_Object_ptr theShape,
227 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
228 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
229 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
230 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
232 //Set a not done flag
233 GetOperations()->SetNotDone();
235 if (theShape == NULL) return;
237 //Get the reference shape
238 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
239 (theShape->GetStudyID(), theShape->GetEntry());
241 if (aShape.IsNull()) return;
243 // Get shape parameters
244 GetOperations()->GetInertia(aShape,
251 //=============================================================================
255 //=============================================================================
256 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
257 CORBA::Double& Xmin, CORBA::Double& Xmax,
258 CORBA::Double& Ymin, CORBA::Double& Ymax,
259 CORBA::Double& Zmin, CORBA::Double& Zmax)
261 //Set a not done flag
262 GetOperations()->SetNotDone();
264 if (theShape == NULL) return;
266 //Get the reference shape
267 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
268 (theShape->GetStudyID(), theShape->GetEntry());
270 if (aShape.IsNull()) return;
272 // Get shape parameters
273 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
276 //=============================================================================
280 //=============================================================================
281 void GEOM_IMeasureOperations_i::GetTolerance
282 (GEOM::GEOM_Object_ptr theShape,
283 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
284 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
285 CORBA::Double& VertMin, CORBA::Double& VertMax)
287 //Set a not done flag
288 GetOperations()->SetNotDone();
290 if (theShape == NULL) return;
292 //Get the reference shape
293 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
294 (theShape->GetStudyID(), theShape->GetEntry());
296 if (aShape.IsNull()) return;
298 // Get shape parameters
299 GetOperations()->GetTolerance(aShape,
305 //=============================================================================
309 //=============================================================================
310 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
311 CORBA::String_out theDescription)
313 //Set a not done flag
314 GetOperations()->SetNotDone();
316 if (theShape == NULL)
318 theDescription = CORBA::string_dup("null");
322 //Get the reference shape
323 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
324 (theShape->GetStudyID(), theShape->GetEntry());
328 theDescription = CORBA::string_dup("null2");
332 // Get shape parameters
333 TCollection_AsciiString aDump;
334 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
336 theDescription = CORBA::string_dup("OK");
339 theDescription = CORBA::string_dup(aDump.ToCString());
343 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
344 CORBA::String_out theDescription)
346 //Set a not done flag
347 GetOperations()->SetNotDone();
349 if (theShape == NULL)
351 theDescription = CORBA::string_dup("null");
355 //Get the reference shape
356 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
357 (theShape->GetStudyID(), theShape->GetEntry());
361 theDescription = CORBA::string_dup("null2");
365 // Get shape parameters
366 TCollection_AsciiString aDump;
367 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
369 theDescription = CORBA::string_dup("OK");
372 theDescription = CORBA::string_dup(aDump.ToCString());
376 //=============================================================================
380 //=============================================================================
381 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
383 //Set a not done flag
384 GetOperations()->SetNotDone();
386 if (theShape == NULL) return NULL;
388 //Get the reference shape
389 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
390 (theShape->GetStudyID(), theShape->GetEntry());
392 if (aShape.IsNull()) return NULL;
394 // Get shape parameters
395 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
396 return CORBA::string_dup(aDescription.ToCString());
399 //=============================================================================
403 //=============================================================================
404 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
405 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
406 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
407 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
409 //Set a not done flag
410 GetOperations()->SetNotDone();
412 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
414 //Get the reference shape
415 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
416 (theShape1->GetStudyID(), theShape1->GetEntry());
417 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
418 (theShape2->GetStudyID(), theShape2->GetEntry());
420 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
422 // Get shape parameters
423 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
426 //=============================================================================
430 //=============================================================================
431 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
432 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
435 //Set a not done flag
436 GetOperations()->SetNotDone();
438 if ( theShape->_is_nil() )
441 //Get the reference shape
442 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
443 theShape->GetStudyID(), theShape->GetEntry() );
445 if ( aShape.IsNull() )
448 // Get shape parameters
449 GetOperations()->PointCoordinates( aShape, X, Y, Z );
452 //=============================================================================
456 //=============================================================================
457 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
458 GEOM::GEOM_Object_ptr theShape2)
460 //Set a not done flag
461 GetOperations()->SetNotDone();
463 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
465 //Get the reference shapes
466 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
467 (theShape1->GetStudyID(), theShape1->GetEntry());
468 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
469 (theShape2->GetStudyID(), theShape2->GetEntry());
471 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
474 return GetOperations()->GetAngle(aShape1, aShape2);
478 //=============================================================================
480 * CurveCurvatureByParam
482 //=============================================================================
483 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
484 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
486 //Set a not done flag
487 GetOperations()->SetNotDone();
489 if(theCurve==NULL) return -1.0;
491 //Get the reference shape
492 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
493 (theCurve->GetStudyID(), theCurve->GetEntry());
495 if(aShape.IsNull()) return -1.0;
497 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
501 //=============================================================================
503 * CurveCurvatureByPoint
505 //=============================================================================
506 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
507 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
509 //Set a not done flag
510 GetOperations()->SetNotDone();
512 if( theCurve==NULL || thePoint==NULL ) return -1.0;
514 //Get the reference shape
515 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
516 (theCurve->GetStudyID(), theCurve->GetEntry());
517 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
518 (thePoint->GetStudyID(), thePoint->GetEntry());
520 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
522 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
526 //=============================================================================
528 * MaxSurfaceCurvatureByParam
530 //=============================================================================
531 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
532 (GEOM::GEOM_Object_ptr theSurf,
533 CORBA::Double theUParam,
534 CORBA::Double theVParam)
536 //Set a not done flag
537 GetOperations()->SetNotDone();
539 if(theSurf==NULL) return -1.0;
541 //Get the reference shape
542 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
543 (theSurf->GetStudyID(), theSurf->GetEntry());
545 if(aShape.IsNull()) return -1.0;
547 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
551 //=============================================================================
553 * MaxSurfaceCurvatureByPoint
555 //=============================================================================
556 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
557 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
559 //Set a not done flag
560 GetOperations()->SetNotDone();
562 if( theSurf==NULL || thePoint==NULL ) return -1.0;
564 //Get the reference shape
565 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
566 (theSurf->GetStudyID(), theSurf->GetEntry());
567 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
568 (thePoint->GetStudyID(), thePoint->GetEntry());
570 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
572 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
576 //=============================================================================
578 * MinSurfaceCurvatureByParam
580 //=============================================================================
581 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
582 (GEOM::GEOM_Object_ptr theSurf,
583 CORBA::Double theUParam,
584 CORBA::Double theVParam)
586 //Set a not done flag
587 GetOperations()->SetNotDone();
589 if(theSurf==NULL) return -1.0;
591 //Get the reference shape
592 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
593 (theSurf->GetStudyID(), theSurf->GetEntry());
595 if(aShape.IsNull()) return -1.0;
597 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
601 //=============================================================================
603 * MinSurfaceCurvatureByPoint
605 //=============================================================================
606 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
607 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
609 //Set a not done flag
610 GetOperations()->SetNotDone();
612 if( theSurf==NULL || thePoint==NULL ) return -1.0;
614 //Get the reference shape
615 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
616 (theSurf->GetStudyID(), theSurf->GetEntry());
617 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
618 (thePoint->GetStudyID(), thePoint->GetEntry());
620 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
622 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);