1 // Copyright (C) 2007-2008 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 = GetOperations()->GetEngine()->GetObject
73 (theShape->GetStudyID(), theShape->GetEntry());
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 if (theShape == NULL) return;
122 //Get the reference shape
123 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
124 (theShape->GetStudyID(), theShape->GetEntry());
126 if (aShape.IsNull()) return;
128 // Get shape parameters
129 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
132 //=============================================================================
136 //=============================================================================
137 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
138 (GEOM::GEOM_Object_ptr theShape)
140 GEOM::GEOM_Object_var aGEOMObject;
142 //Set a not done flag
143 GetOperations()->SetNotDone();
145 if (CORBA::is_nil(theShape)) return aGEOMObject._retn();
147 //Get the reference shape
148 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
149 (theShape->GetStudyID(), theShape->GetEntry());
151 if (aShape.IsNull()) return aGEOMObject._retn();
153 // Make Point - centre of mass of theShape
154 Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
155 if (!GetOperations()->IsDone() || anObject.IsNull())
156 return aGEOMObject._retn();
158 return GetObject(anObject);
161 //=============================================================================
165 //=============================================================================
166 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
167 (GEOM::GEOM_Object_ptr theFace,
168 GEOM::GEOM_Object_ptr theOptionalPoint)
170 GEOM::GEOM_Object_var aGEOMObject;
172 //Set a not done flag
173 GetOperations()->SetNotDone();
175 if (CORBA::is_nil(theFace)) return aGEOMObject._retn();
177 //Get the reference shape
178 Handle(GEOM_Object) aFace = GetOperations()->GetEngine()->GetObject
179 (theFace->GetStudyID(), theFace->GetEntry());
181 if (aFace.IsNull()) return aGEOMObject._retn();
183 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
184 Handle(GEOM_Object) anOptionalPoint;
185 if (!CORBA::is_nil(theOptionalPoint)) {
186 anOptionalPoint = GetOperations()->GetEngine()->GetObject
187 (theOptionalPoint->GetStudyID(), theOptionalPoint->GetEntry());
189 Handle(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
190 if (!GetOperations()->IsDone() || anObject.IsNull())
191 return aGEOMObject._retn();
193 return GetObject(anObject);
196 //=============================================================================
200 //=============================================================================
201 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
202 CORBA::Double& theLength,
203 CORBA::Double& theSurfArea,
204 CORBA::Double& theVolume)
206 //Set a not done flag
207 GetOperations()->SetNotDone();
209 if (theShape == NULL) return;
211 //Get the reference shape
212 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
213 (theShape->GetStudyID(), theShape->GetEntry());
215 if (aShape.IsNull()) return;
217 // Get shape parameters
218 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
221 //=============================================================================
225 //=============================================================================
226 void GEOM_IMeasureOperations_i::GetInertia
227 (GEOM::GEOM_Object_ptr theShape,
228 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
229 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
230 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
231 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
233 //Set a not done flag
234 GetOperations()->SetNotDone();
236 if (theShape == NULL) return;
238 //Get the reference shape
239 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
240 (theShape->GetStudyID(), theShape->GetEntry());
242 if (aShape.IsNull()) return;
244 // Get shape parameters
245 GetOperations()->GetInertia(aShape,
252 //=============================================================================
256 //=============================================================================
257 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
258 CORBA::Double& Xmin, CORBA::Double& Xmax,
259 CORBA::Double& Ymin, CORBA::Double& Ymax,
260 CORBA::Double& Zmin, CORBA::Double& Zmax)
262 //Set a not done flag
263 GetOperations()->SetNotDone();
265 if (theShape == NULL) return;
267 //Get the reference shape
268 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
269 (theShape->GetStudyID(), theShape->GetEntry());
271 if (aShape.IsNull()) return;
273 // Get shape parameters
274 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
277 //=============================================================================
281 //=============================================================================
282 void GEOM_IMeasureOperations_i::GetTolerance
283 (GEOM::GEOM_Object_ptr theShape,
284 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
285 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
286 CORBA::Double& VertMin, CORBA::Double& VertMax)
288 //Set a not done flag
289 GetOperations()->SetNotDone();
291 if (theShape == NULL) return;
293 //Get the reference shape
294 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
295 (theShape->GetStudyID(), theShape->GetEntry());
297 if (aShape.IsNull()) return;
299 // Get shape parameters
300 GetOperations()->GetTolerance(aShape,
306 //=============================================================================
310 //=============================================================================
311 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
312 CORBA::String_out theDescription)
314 //Set a not done flag
315 GetOperations()->SetNotDone();
317 if (theShape == NULL)
319 theDescription = CORBA::string_dup("null");
323 //Get the reference shape
324 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
325 (theShape->GetStudyID(), theShape->GetEntry());
329 theDescription = CORBA::string_dup("null2");
333 // Get shape parameters
334 TCollection_AsciiString aDump;
335 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
337 theDescription = CORBA::string_dup("OK");
340 theDescription = CORBA::string_dup(aDump.ToCString());
344 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
345 CORBA::String_out theDescription)
347 //Set a not done flag
348 GetOperations()->SetNotDone();
350 if (theShape == NULL)
352 theDescription = CORBA::string_dup("null");
356 //Get the reference shape
357 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
358 (theShape->GetStudyID(), theShape->GetEntry());
362 theDescription = CORBA::string_dup("null2");
366 // Get shape parameters
367 TCollection_AsciiString aDump;
368 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
370 theDescription = CORBA::string_dup("OK");
373 theDescription = CORBA::string_dup(aDump.ToCString());
377 //=============================================================================
381 //=============================================================================
382 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
384 //Set a not done flag
385 GetOperations()->SetNotDone();
387 if (theShape == NULL) return NULL;
389 //Get the reference shape
390 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
391 (theShape->GetStudyID(), theShape->GetEntry());
393 if (aShape.IsNull()) return NULL;
395 // Get shape parameters
396 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
397 return CORBA::string_dup(aDescription.ToCString());
400 //=============================================================================
404 //=============================================================================
405 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
406 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
407 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
408 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
410 //Set a not done flag
411 GetOperations()->SetNotDone();
413 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
415 //Get the reference shape
416 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
417 (theShape1->GetStudyID(), theShape1->GetEntry());
418 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
419 (theShape2->GetStudyID(), theShape2->GetEntry());
421 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
423 // Get shape parameters
424 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
427 //=============================================================================
431 //=============================================================================
432 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
433 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
436 //Set a not done flag
437 GetOperations()->SetNotDone();
439 if ( theShape->_is_nil() )
442 //Get the reference shape
443 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
444 theShape->GetStudyID(), theShape->GetEntry() );
446 if ( aShape.IsNull() )
449 // Get shape parameters
450 GetOperations()->PointCoordinates( aShape, X, Y, Z );
453 //=============================================================================
457 //=============================================================================
458 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
459 GEOM::GEOM_Object_ptr theShape2)
461 //Set a not done flag
462 GetOperations()->SetNotDone();
464 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
466 //Get the reference shapes
467 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
468 (theShape1->GetStudyID(), theShape1->GetEntry());
469 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
470 (theShape2->GetStudyID(), theShape2->GetEntry());
472 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
475 return GetOperations()->GetAngle(aShape1, aShape2);
479 //=============================================================================
481 * CurveCurvatureByParam
483 //=============================================================================
484 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
485 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
487 //Set a not done flag
488 GetOperations()->SetNotDone();
490 if(theCurve==NULL) return -1.0;
492 //Get the reference shape
493 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
494 (theCurve->GetStudyID(), theCurve->GetEntry());
496 if(aShape.IsNull()) return -1.0;
498 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
502 //=============================================================================
504 * CurveCurvatureByPoint
506 //=============================================================================
507 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
508 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
510 //Set a not done flag
511 GetOperations()->SetNotDone();
513 if( theCurve==NULL || thePoint==NULL ) return -1.0;
515 //Get the reference shape
516 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
517 (theCurve->GetStudyID(), theCurve->GetEntry());
518 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
519 (thePoint->GetStudyID(), thePoint->GetEntry());
521 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
523 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
527 //=============================================================================
529 * MaxSurfaceCurvatureByParam
531 //=============================================================================
532 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
533 (GEOM::GEOM_Object_ptr theSurf,
534 CORBA::Double theUParam,
535 CORBA::Double theVParam)
537 //Set a not done flag
538 GetOperations()->SetNotDone();
540 if(theSurf==NULL) return -1.0;
542 //Get the reference shape
543 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
544 (theSurf->GetStudyID(), theSurf->GetEntry());
546 if(aShape.IsNull()) return -1.0;
548 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
552 //=============================================================================
554 * MaxSurfaceCurvatureByPoint
556 //=============================================================================
557 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
558 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
560 //Set a not done flag
561 GetOperations()->SetNotDone();
563 if( theSurf==NULL || thePoint==NULL ) return -1.0;
565 //Get the reference shape
566 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
567 (theSurf->GetStudyID(), theSurf->GetEntry());
568 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
569 (thePoint->GetStudyID(), thePoint->GetEntry());
571 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
573 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
577 //=============================================================================
579 * MinSurfaceCurvatureByParam
581 //=============================================================================
582 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
583 (GEOM::GEOM_Object_ptr theSurf,
584 CORBA::Double theUParam,
585 CORBA::Double theVParam)
587 //Set a not done flag
588 GetOperations()->SetNotDone();
590 if(theSurf==NULL) return -1.0;
592 //Get the reference shape
593 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
594 (theSurf->GetStudyID(), theSurf->GetEntry());
596 if(aShape.IsNull()) return -1.0;
598 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
602 //=============================================================================
604 * MinSurfaceCurvatureByPoint
606 //=============================================================================
607 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
608 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
610 //Set a not done flag
611 GetOperations()->SetNotDone();
613 if( theSurf==NULL || thePoint==NULL ) return -1.0;
615 //Get the reference shape
616 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
617 (theSurf->GetStudyID(), theSurf->GetEntry());
618 Handle(GEOM_Object) aPoint = GetOperations()->GetEngine()->GetObject
619 (thePoint->GetStudyID(), thePoint->GetEntry());
621 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
623 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);