1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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"
34 * This function converts shape errors from theErrorsFrom to theErrorsTo.
35 * Note that theErrorsTo is not cleared at first.
37 * \param theErrorsFrom errors to be converted.
38 * \param theErrorsTo result errors.
40 static void ConvertShapeError
41 (const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrorsFrom,
42 std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsTo)
44 int aNbErr = theErrorsFrom.length();
47 for (; i < aNbErr; i++) {
48 const GEOM::GEOM_IMeasureOperations::ShapeError anErr = theErrorsFrom[i];
49 const GEOM::GEOM_IMeasureOperations::ShapeErrorType aType = anErr.error;
50 const GEOM::ListOfLong anIncrims = anErr.incriminated;
51 GEOMImpl_IMeasureOperations::ShapeError anErrStruct;
54 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve:
55 anErrStruct.error = BRepCheck_InvalidPointOnCurve;
57 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface:
58 anErrStruct.error = BRepCheck_InvalidPointOnCurveOnSurface;
60 case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface:
61 anErrStruct.error = BRepCheck_InvalidPointOnSurface;
63 case GEOM::GEOM_IMeasureOperations::No3DCurve:
64 anErrStruct.error = BRepCheck_No3DCurve;
66 case GEOM::GEOM_IMeasureOperations::Multiple3DCurve:
67 anErrStruct.error = BRepCheck_Multiple3DCurve;
69 case GEOM::GEOM_IMeasureOperations::Invalid3DCurve:
70 anErrStruct.error = BRepCheck_Invalid3DCurve;
72 case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface:
73 anErrStruct.error = BRepCheck_NoCurveOnSurface;
75 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface:
76 anErrStruct.error = BRepCheck_InvalidCurveOnSurface;
78 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface:
79 anErrStruct.error = BRepCheck_InvalidCurveOnClosedSurface;
81 case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag:
82 anErrStruct.error = BRepCheck_InvalidSameRangeFlag;
84 case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag:
85 anErrStruct.error = BRepCheck_InvalidSameParameterFlag;
87 case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag:
88 anErrStruct.error = BRepCheck_InvalidDegeneratedFlag;
90 case GEOM::GEOM_IMeasureOperations::FreeEdge:
91 anErrStruct.error = BRepCheck_FreeEdge;
93 case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity:
94 anErrStruct.error = BRepCheck_InvalidMultiConnexity;
96 case GEOM::GEOM_IMeasureOperations::InvalidRange:
97 anErrStruct.error = BRepCheck_InvalidRange;
99 case GEOM::GEOM_IMeasureOperations::EmptyWire:
100 anErrStruct.error = BRepCheck_EmptyWire;
102 case GEOM::GEOM_IMeasureOperations::RedundantEdge:
103 anErrStruct.error = BRepCheck_RedundantEdge;
105 case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire:
106 anErrStruct.error = BRepCheck_SelfIntersectingWire;
108 case GEOM::GEOM_IMeasureOperations::NoSurface:
109 anErrStruct.error = BRepCheck_NoSurface;
111 case GEOM::GEOM_IMeasureOperations::InvalidWire:
112 anErrStruct.error = BRepCheck_InvalidWire;
114 case GEOM::GEOM_IMeasureOperations::RedundantWire:
115 anErrStruct.error = BRepCheck_RedundantWire;
117 case GEOM::GEOM_IMeasureOperations::IntersectingWires:
118 anErrStruct.error = BRepCheck_IntersectingWires;
120 case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires:
121 anErrStruct.error = BRepCheck_InvalidImbricationOfWires;
123 case GEOM::GEOM_IMeasureOperations::EmptyShell:
124 anErrStruct.error = BRepCheck_EmptyShell;
126 case GEOM::GEOM_IMeasureOperations::RedundantFace:
127 anErrStruct.error = BRepCheck_RedundantFace;
129 case GEOM::GEOM_IMeasureOperations::UnorientableShape:
130 anErrStruct.error = BRepCheck_UnorientableShape;
132 case GEOM::GEOM_IMeasureOperations::NotClosed:
133 anErrStruct.error = BRepCheck_NotClosed;
135 case GEOM::GEOM_IMeasureOperations::NotConnected:
136 anErrStruct.error = BRepCheck_NotConnected;
138 case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape:
139 anErrStruct.error = BRepCheck_SubshapeNotInShape;
141 case GEOM::GEOM_IMeasureOperations::BadOrientation:
142 anErrStruct.error = BRepCheck_BadOrientation;
144 case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape:
145 anErrStruct.error = BRepCheck_BadOrientationOfSubshape;
147 case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue:
148 anErrStruct.error = BRepCheck_InvalidToleranceValue;
150 case GEOM::GEOM_IMeasureOperations::CheckFail:
151 anErrStruct.error = BRepCheck_CheckFail;
158 int aLen = anIncrims.length();
160 for (; ii < aLen; ii++) {
161 anErrStruct.incriminated.push_back(anIncrims[ii]);
164 theErrorsTo.push_back(anErrStruct);
169 * This function converts shape errors from theErrorsFrom to theErrorsTo.
170 * Note that theErrorsTo is not cleared at first.
172 * \param theErrorsFrom errors to be converted.
173 * \param theErrorsTo result errors.
175 static void ConvertShapeError
176 (const std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsFrom,
177 GEOM::GEOM_IMeasureOperations::ShapeErrors_out &theErrorsTo)
179 const int aNbErr = theErrorsFrom.size();
180 GEOM::GEOM_IMeasureOperations::ShapeErrors_var anErrArray =
181 new GEOM::GEOM_IMeasureOperations::ShapeErrors;
183 anErrArray->length(aNbErr);
185 // fill the local CORBA array with values from lists
186 std::list<GEOMImpl_IMeasureOperations::ShapeError>::const_iterator
187 anIt = theErrorsFrom.begin();
190 for (; anIt != theErrorsFrom.end(); i++, anIt++) {
191 GEOM::GEOM_IMeasureOperations::ShapeError_var anErrStruct =
192 new GEOM::GEOM_IMeasureOperations::ShapeError;
194 switch (anIt->error) {
195 case BRepCheck_InvalidPointOnCurve:
196 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve;
198 case BRepCheck_InvalidPointOnCurveOnSurface:
199 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface;
201 case BRepCheck_InvalidPointOnSurface:
202 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface;
204 case BRepCheck_No3DCurve:
205 anErrStruct->error = GEOM::GEOM_IMeasureOperations::No3DCurve;
207 case BRepCheck_Multiple3DCurve:
208 anErrStruct->error = GEOM::GEOM_IMeasureOperations::Multiple3DCurve;
210 case BRepCheck_Invalid3DCurve:
211 anErrStruct->error = GEOM::GEOM_IMeasureOperations::Invalid3DCurve;
213 case BRepCheck_NoCurveOnSurface:
214 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoCurveOnSurface;
216 case BRepCheck_InvalidCurveOnSurface:
217 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface;
219 case BRepCheck_InvalidCurveOnClosedSurface:
220 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface;
222 case BRepCheck_InvalidSameRangeFlag:
223 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag;
225 case BRepCheck_InvalidSameParameterFlag:
226 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag;
228 case BRepCheck_InvalidDegeneratedFlag:
229 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag;
231 case BRepCheck_FreeEdge:
232 anErrStruct->error = GEOM::GEOM_IMeasureOperations::FreeEdge;
234 case BRepCheck_InvalidMultiConnexity:
235 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity;
237 case BRepCheck_InvalidRange:
238 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidRange;
240 case BRepCheck_EmptyWire:
241 anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyWire;
243 case BRepCheck_RedundantEdge:
244 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantEdge;
246 case BRepCheck_SelfIntersectingWire:
247 anErrStruct->error = GEOM::GEOM_IMeasureOperations::SelfIntersectingWire;
249 case BRepCheck_NoSurface:
250 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoSurface;
252 case BRepCheck_InvalidWire:
253 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidWire;
255 case BRepCheck_RedundantWire:
256 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantWire;
258 case BRepCheck_IntersectingWires:
259 anErrStruct->error = GEOM::GEOM_IMeasureOperations::IntersectingWires;
261 case BRepCheck_InvalidImbricationOfWires:
262 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires;
264 case BRepCheck_EmptyShell:
265 anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyShell;
267 case BRepCheck_RedundantFace:
268 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantFace;
270 case BRepCheck_UnorientableShape:
271 anErrStruct->error = GEOM::GEOM_IMeasureOperations::UnorientableShape;
273 case BRepCheck_NotClosed:
274 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotClosed;
276 case BRepCheck_NotConnected:
277 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotConnected;
279 case BRepCheck_SubshapeNotInShape:
280 anErrStruct->error = GEOM::GEOM_IMeasureOperations::SubshapeNotInShape;
282 case BRepCheck_BadOrientation:
283 anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientation;
285 case BRepCheck_BadOrientationOfSubshape:
286 anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape;
288 case BRepCheck_InvalidToleranceValue:
289 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidToleranceValue;
291 case BRepCheck_CheckFail:
292 anErrStruct->error = GEOM::GEOM_IMeasureOperations::CheckFail;
298 std::list<int> aIndList = anIt->incriminated;
299 GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
300 anIncrims->length(aIndList.size());
302 std::list<int>::iterator anIndIt = aIndList.begin();
305 for (; anIndIt != aIndList.end(); jj++, anIndIt++) {
306 anIncrims[jj] = *anIndIt;
309 anErrStruct->incriminated = anIncrims;
311 anErrArray[i] = anErrStruct;
314 // initialize out-parameter with local array
315 theErrorsTo = anErrArray._retn();
318 //=============================================================================
322 //=============================================================================
323 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
324 GEOM::GEOM_Gen_ptr theEngine,
325 ::GEOMImpl_IMeasureOperations* theImpl)
326 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
328 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
331 //=============================================================================
335 //=============================================================================
336 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
338 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
341 //=============================================================================
345 //=============================================================================
346 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
347 (GEOM::GEOM_Object_ptr theShape,
348 GEOM::ListOfLong_out theIntegers,
349 GEOM::ListOfDouble_out theDoubles)
351 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
353 // allocate the CORBA arrays
354 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
355 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
357 //Get the reference shape
358 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
360 if (!aShape.IsNull()) {
361 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
362 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
364 // Detect kind of shape and parameters
365 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
367 int nbInts = anIntegers->Length();
368 int nbDbls = aDoubles->Length();
370 anIntegersArray->length(nbInts);
371 aDoublesArray->length(nbDbls);
373 for (int ii = 0; ii < nbInts; ii++) {
374 anIntegersArray[ii] = anIntegers->Value(ii + 1);
376 for (int id = 0; id < nbDbls; id++) {
377 aDoublesArray[id] = aDoubles->Value(id + 1);
381 // initialize out-parameters with local arrays
382 theIntegers = anIntegersArray._retn();
383 theDoubles = aDoublesArray._retn();
384 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
387 //=============================================================================
391 //=============================================================================
392 void GEOM_IMeasureOperations_i::GetPosition
393 (GEOM::GEOM_Object_ptr theShape,
394 CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
395 CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
396 CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
398 //Set a not done flag
399 GetOperations()->SetNotDone();
401 //Set default values: global CS
402 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
405 //Get the reference shape
406 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
407 if (aShape.IsNull()) return;
409 // Get shape parameters
410 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
413 //=============================================================================
417 //=============================================================================
418 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
419 (GEOM::GEOM_Object_ptr theShape)
421 GEOM::GEOM_Object_var aGEOMObject;
423 //Set a not done flag
424 GetOperations()->SetNotDone();
426 //Get the reference shape
427 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
428 if (aShape.IsNull()) return aGEOMObject._retn();
430 // Make Point - centre of mass of theShape
431 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
432 if (!GetOperations()->IsDone() || anObject.IsNull())
433 return aGEOMObject._retn();
435 return GetObject(anObject);
438 //=============================================================================
442 //=============================================================================
443 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetVertexByIndex
444 (GEOM::GEOM_Object_ptr theShape, CORBA::Long theIndex)
446 GEOM::GEOM_Object_var aGEOMObject;
448 //Set a not done flag
449 GetOperations()->SetNotDone();
451 //Get the reference shape
452 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
453 if ( aShape.IsNull() ) return aGEOMObject._retn();
455 // Get vertex by index
456 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex);
457 if (!GetOperations()->IsDone() || anObject.IsNull())
458 return aGEOMObject._retn();
460 return GetObject(anObject);
463 //=============================================================================
467 //=============================================================================
468 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
469 (GEOM::GEOM_Object_ptr theFace,
470 GEOM::GEOM_Object_ptr theOptionalPoint)
472 GEOM::GEOM_Object_var aGEOMObject;
474 //Set a not done flag
475 GetOperations()->SetNotDone();
477 //Get the reference shape
478 HANDLE_NAMESPACE(GEOM_Object) aFace = GetObjectImpl(theFace);
479 if (aFace.IsNull()) return aGEOMObject._retn();
481 // Get the OptionalPoint (can be not defined)
482 HANDLE_NAMESPACE(GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
484 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
485 HANDLE_NAMESPACE(GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
486 if (!GetOperations()->IsDone() || anObject.IsNull())
487 return aGEOMObject._retn();
489 return GetObject(anObject);
492 //=============================================================================
496 //=============================================================================
497 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
498 CORBA::Double& theLength,
499 CORBA::Double& theSurfArea,
500 CORBA::Double& theVolume)
502 //Set a not done flag
503 GetOperations()->SetNotDone();
505 //Get the reference shape
506 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
507 if (aShape.IsNull()) return;
509 // Get shape parameters
510 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
513 //=============================================================================
517 //=============================================================================
518 void GEOM_IMeasureOperations_i::GetInertia
519 (GEOM::GEOM_Object_ptr theShape,
520 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
521 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
522 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
523 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
525 //Set a not done flag
526 GetOperations()->SetNotDone();
528 //Get the reference shape
529 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
530 if (aShape.IsNull()) return;
532 // Get shape parameters
533 GetOperations()->GetInertia(aShape,
540 //=============================================================================
544 //=============================================================================
545 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
546 CORBA::Boolean precise,
547 CORBA::Double& Xmin, CORBA::Double& Xmax,
548 CORBA::Double& Ymin, CORBA::Double& Ymax,
549 CORBA::Double& Zmin, CORBA::Double& Zmax)
551 //Set a not done flag
552 GetOperations()->SetNotDone();
554 //Get the reference shape
555 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
556 if (aShape.IsNull()) return;
558 // Get shape parameters
559 GetOperations()->GetBoundingBox
560 (aShape, precise, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
563 //=============================================================================
567 //=============================================================================
568 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
569 (GEOM::GEOM_Object_ptr theShape,
570 CORBA::Boolean precise)
572 GEOM::GEOM_Object_var aGEOMObject;
574 //Set a not done flag
575 GetOperations()->SetNotDone();
577 //Get the reference shape
578 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
579 if (aShape.IsNull()) return aGEOMObject._retn();
581 // Make Box - bounding box of theShape
582 HANDLE_NAMESPACE(GEOM_Object) anObject =
583 GetOperations()->GetBoundingBox(aShape, precise);
584 if (!GetOperations()->IsDone() || anObject.IsNull())
585 return aGEOMObject._retn();
587 return GetObject(anObject);
590 //=============================================================================
594 //=============================================================================
595 void GEOM_IMeasureOperations_i::GetTolerance
596 (GEOM::GEOM_Object_ptr theShape,
597 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
598 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
599 CORBA::Double& VertMin, CORBA::Double& VertMax)
601 //Set a not done flag
602 GetOperations()->SetNotDone();
604 //Get the reference shape
605 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
606 if (aShape.IsNull()) return;
608 // Get shape parameters
609 GetOperations()->GetTolerance(aShape,
615 //=============================================================================
619 //=============================================================================
620 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape
621 (GEOM::GEOM_Object_ptr theShape,
622 GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
624 //Set a not done flag
625 GetOperations()->SetNotDone();
627 if (CORBA::is_nil(theShape))
632 //Get the reference shape
633 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
640 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
641 bool isOk = GetOperations()->CheckShape(aShape, false, anErrList);
643 ConvertShapeError(anErrList, theErrors);
648 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry
649 (GEOM::GEOM_Object_ptr theShape,
650 GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
652 //Set a not done flag
653 GetOperations()->SetNotDone();
655 if (CORBA::is_nil(theShape))
660 //Get the reference shape
661 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
668 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
669 bool isOk = GetOperations()->CheckShape(aShape, true, anErrList);
671 ConvertShapeError(anErrList, theErrors);
676 //=============================================================================
680 //=============================================================================
681 char* GEOM_IMeasureOperations_i::PrintShapeErrors
682 ( GEOM::GEOM_Object_ptr theShape,
683 const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors)
685 //Get the reference shape
686 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
688 if (aShape.IsNull()) {
692 // Convert the errors sequence
693 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
695 ConvertShapeError(theErrors, anErrList);
697 TCollection_AsciiString aDescr =
698 GetOperations()->PrintShapeErrors(aShape, anErrList);
700 return CORBA::string_dup(aDescr.ToCString());
703 //=============================================================================
705 * CheckSelfIntersections
707 //=============================================================================
708 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
709 CORBA::Long theCheckLevel,
710 GEOM::ListOfLong_out theIntersections)
712 // Set a not done flag
713 GetOperations()->SetNotDone();
717 // Allocate the CORBA arrays
718 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
720 // Get the reference shape
721 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
723 if (!aShape.IsNull()) {
724 GEOMImpl_IMeasureOperations::SICheckLevel aCheckLevel;
726 switch(theCheckLevel) {
728 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_V;
731 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_E;
734 aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_E;
737 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_F;
740 aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_F;
744 aCheckLevel = GEOMImpl_IMeasureOperations::SI_ALL;
748 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
750 // Detect self-intersections
751 isGood = GetOperations()->CheckSelfIntersections
752 (aShape, aCheckLevel, anIntegers);
754 int nbInts = anIntegers->Length();
756 anIntegersArray->length(nbInts);
758 for (int ii = 0; ii < nbInts; ii++) {
759 anIntegersArray[ii] = anIntegers->Value(ii + 1);
763 // Initialize out-parameters with local arrays
764 theIntersections = anIntegersArray._retn();
768 //=============================================================================
770 * CheckSelfIntersectionsFast
772 //=============================================================================
773 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersectionsFast
774 (GEOM::GEOM_Object_ptr theShape,
775 CORBA::Float theDeflection,
776 CORBA::Double theTolerance,
777 GEOM::ListOfLong_out theIntersections)
779 // Set a not done flag
780 GetOperations()->SetNotDone();
784 // Allocate the CORBA arrays
785 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
787 // Get the reference shape
788 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
790 if (!aShape.IsNull()) {
791 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
793 // Detect self-intersections
794 isGood = GetOperations()->CheckSelfIntersectionsFast
795 (aShape, theDeflection, theTolerance, anIntegers);
797 int nbInts = anIntegers->Length();
799 anIntegersArray->length(nbInts);
801 for (int ii = 0; ii < nbInts; ii++) {
802 anIntegersArray[ii] = anIntegers->Value(ii + 1);
806 // Initialize out-parameters with local arrays
807 theIntersections = anIntegersArray._retn();
811 //=============================================================================
815 //=============================================================================
816 CORBA::Boolean GEOM_IMeasureOperations_i::CheckBOPArguments
817 (GEOM::GEOM_Object_ptr theShape)
819 // Set a not done flag
820 GetOperations()->SetNotDone();
822 // Get the reference shape
823 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
826 if (!aShape.IsNull()) {
827 // Check BOP agruments
828 isGood = GetOperations()->CheckBOPArguments(aShape);
834 //=============================================================================
838 //=============================================================================
839 CORBA::Boolean GEOM_IMeasureOperations_i::FastIntersect (GEOM::GEOM_Object_ptr theShape1,
840 GEOM::GEOM_Object_ptr theShape2,
841 CORBA::Double theTolerance,
842 CORBA::Float theDeflection,
843 GEOM::ListOfLong_out theIntersections1,
844 GEOM::ListOfLong_out theIntersections2)
846 // Set a not done flag
847 GetOperations()->SetNotDone();
851 // Allocate the CORBA arrays
852 GEOM::ListOfLong_var anIntegersArray1 = new GEOM::ListOfLong();
853 GEOM::ListOfLong_var anIntegersArray2 = new GEOM::ListOfLong();
855 // Get the reference shape
856 HANDLE_NAMESPACE(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
857 HANDLE_NAMESPACE(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
859 if (!aShape1.IsNull() && !aShape2.IsNull()) {
860 Handle(TColStd_HSequenceOfInteger) anIntegers1 = new TColStd_HSequenceOfInteger;
861 Handle(TColStd_HSequenceOfInteger) anIntegers2 = new TColStd_HSequenceOfInteger;
863 // Detect intersections
864 isGood = GetOperations()->FastIntersect
865 (aShape1, aShape2, theTolerance, theDeflection, anIntegers1, anIntegers2);
867 int nbInts1 = anIntegers1->Length();
868 int nbInts2 = anIntegers2->Length();
870 anIntegersArray1->length(nbInts1);
871 anIntegersArray2->length(nbInts2);
873 for (int ii = 0; ii < nbInts1; ii++) {
874 anIntegersArray1[ii] = anIntegers1->Value(ii + 1);
876 for (int ii = 0; ii < nbInts2; ii++) {
877 anIntegersArray2[ii] = anIntegers2->Value(ii + 1);
881 // Initialize out-parameters with local arrays
882 theIntersections1 = anIntegersArray1._retn();
883 theIntersections2 = anIntegersArray2._retn();
887 //=============================================================================
891 //=============================================================================
892 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
894 //Set a not done flag
895 GetOperations()->SetNotDone();
897 //Get the reference shape
898 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
899 if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
901 // Get shape parameters
902 TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
903 return CORBA::string_dup(aDescription.ToCString());
906 //=============================================================================
910 //=============================================================================
911 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
913 //Set a not done flag
914 GetOperations()->SetNotDone();
916 //Get the reference shape
917 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
918 if (aShape.IsNull()) return NULL;
920 // Get shape parameters
921 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
922 return CORBA::string_dup(aDescription.ToCString());
925 //=============================================================================
929 //=============================================================================
930 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
931 const GEOM::ListOfDouble& theCoords,
932 CORBA::Double tolerance)
934 //Set a not done flag
935 GetOperations()->SetNotDone();
937 unsigned int nb_points = theCoords.length()/3;
939 GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
940 aResults->length(nb_points);
942 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
944 std::vector<double> tmp(3*nb_points);
945 for (int i = 0; i < 3*nb_points; i++)
946 tmp[i] = theCoords[i];
947 std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
948 for (int i = 0; i < nb_points; i++)
949 aResults[i] = i < res.size() ? res[i] : false;
950 return aResults._retn();
953 //=============================================================================
957 //=============================================================================
958 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
959 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
960 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
961 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
963 //Set a not done flag
964 GetOperations()->SetNotDone();
966 //Get the reference shape
967 HANDLE_NAMESPACE(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
968 HANDLE_NAMESPACE(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
969 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
971 // Get shape parameters
972 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
975 //=============================================================================
979 //=============================================================================
980 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
981 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
982 GEOM::ListOfDouble_out theCoords)
984 //Set a not done flag
985 GetOperations()->SetNotDone();
987 // allocate the CORBA array
989 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
991 //Get the reference shape
992 HANDLE_NAMESPACE(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
993 HANDLE_NAMESPACE(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
995 if (!aShape1.IsNull() && !aShape2.IsNull()) {
996 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
997 // Get shape parameters
998 nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
999 int nbDbls = aDoubles->Length();
1000 aDoublesArray->length(nbDbls);
1001 for (int id = 0; id < nbDbls; id++) {
1002 aDoublesArray[id] = aDoubles->Value(id + 1);
1006 theCoords = aDoublesArray._retn();
1010 //=============================================================================
1014 //=============================================================================
1015 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
1016 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
1019 //Set a not done flag
1020 GetOperations()->SetNotDone();
1022 //Get the reference shape
1023 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theShape);
1024 if (aShape.IsNull())
1027 // Get shape parameters
1028 GetOperations()->PointCoordinates( aShape, X, Y, Z );
1031 //=============================================================================
1035 //=============================================================================
1036 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
1037 GEOM::GEOM_Object_ptr theShape2)
1039 //Set a not done flag
1040 GetOperations()->SetNotDone();
1042 //Get the reference shapes
1043 HANDLE_NAMESPACE(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1044 HANDLE_NAMESPACE(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1045 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1048 return GetOperations()->GetAngle(aShape1, aShape2);
1051 //=============================================================================
1055 //=============================================================================
1056 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
1057 GEOM::GEOM_Object_ptr theShape2)
1059 //Set a not done flag
1060 GetOperations()->SetNotDone();
1062 //Get the reference shapes
1063 HANDLE_NAMESPACE(GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1064 HANDLE_NAMESPACE(GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1065 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1068 return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
1072 //=============================================================================
1074 * CurveCurvatureByParam
1076 //=============================================================================
1077 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
1078 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
1080 //Set a not done flag
1081 GetOperations()->SetNotDone();
1083 //Get the reference shape
1084 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theCurve);
1085 if(aShape.IsNull()) return -1.0;
1087 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
1090 //=============================================================================
1092 * CurveCurvatureByPoint
1094 //=============================================================================
1095 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
1096 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
1098 //Set a not done flag
1099 GetOperations()->SetNotDone();
1101 //Get the reference shape
1102 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theCurve);
1103 HANDLE_NAMESPACE(GEOM_Object) aPoint = GetObjectImpl(thePoint);
1104 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1106 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
1110 //=============================================================================
1112 * MaxSurfaceCurvatureByParam
1114 //=============================================================================
1115 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
1116 (GEOM::GEOM_Object_ptr theSurf,
1117 CORBA::Double theUParam,
1118 CORBA::Double theVParam)
1120 //Set a not done flag
1121 GetOperations()->SetNotDone();
1123 //Get the reference shape
1124 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theSurf);
1125 if(aShape.IsNull()) return -1.0;
1127 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1130 //=============================================================================
1132 * MaxSurfaceCurvatureByPoint
1134 //=============================================================================
1135 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
1136 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1138 //Set a not done flag
1139 GetOperations()->SetNotDone();
1141 //Get the reference shape
1142 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theSurf);
1143 HANDLE_NAMESPACE(GEOM_Object) aPoint = GetObjectImpl(thePoint);
1144 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1146 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
1149 //=============================================================================
1151 * MinSurfaceCurvatureByParam
1153 //=============================================================================
1154 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
1155 (GEOM::GEOM_Object_ptr theSurf,
1156 CORBA::Double theUParam,
1157 CORBA::Double theVParam)
1159 //Set a not done flag
1160 GetOperations()->SetNotDone();
1162 //Get the reference shape
1163 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theSurf);
1164 if (aShape.IsNull()) return -1.0;
1166 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1169 //=============================================================================
1171 * MinSurfaceCurvatureByPoint
1173 //=============================================================================
1174 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
1175 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1177 //Set a not done flag
1178 GetOperations()->SetNotDone();
1180 //Get the reference shape
1181 HANDLE_NAMESPACE(GEOM_Object) aShape = GetObjectImpl(theSurf);
1182 HANDLE_NAMESPACE(GEOM_Object) aPoint = GetObjectImpl(thePoint);
1183 if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
1185 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);