1 // Copyright (C) 2007-2024 CEA, EDF, 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>
24 #include <TColStd_HArray1OfReal.hxx>
26 #include "GEOM_IMeasureOperations_i.hh"
28 #include "utilities.h"
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
34 #define WRN_SHAPE_IS_NULL "WRN_SHAPE_IS_NULL"
37 * This function converts shape errors from theErrorsFrom to theErrorsTo.
38 * Note that theErrorsTo is not cleared at first.
40 * \param theErrorsFrom errors to be converted.
41 * \param theErrorsTo result errors.
43 static void ConvertShapeError
44 (const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrorsFrom,
45 std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsTo)
47 int aNbErr = theErrorsFrom.length();
50 for (; i < aNbErr; i++) {
51 const GEOM::GEOM_IMeasureOperations::ShapeError anErr = theErrorsFrom[i];
52 const GEOM::GEOM_IMeasureOperations::ShapeErrorType aType = anErr.error;
53 const GEOM::ListOfLong anIncrims = anErr.incriminated;
54 GEOMImpl_IMeasureOperations::ShapeError anErrStruct;
57 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve:
58 anErrStruct.error = BRepCheck_InvalidPointOnCurve;
60 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface:
61 anErrStruct.error = BRepCheck_InvalidPointOnCurveOnSurface;
63 case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface:
64 anErrStruct.error = BRepCheck_InvalidPointOnSurface;
66 case GEOM::GEOM_IMeasureOperations::No3DCurve:
67 anErrStruct.error = BRepCheck_No3DCurve;
69 case GEOM::GEOM_IMeasureOperations::Multiple3DCurve:
70 anErrStruct.error = BRepCheck_Multiple3DCurve;
72 case GEOM::GEOM_IMeasureOperations::Invalid3DCurve:
73 anErrStruct.error = BRepCheck_Invalid3DCurve;
75 case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface:
76 anErrStruct.error = BRepCheck_NoCurveOnSurface;
78 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface:
79 anErrStruct.error = BRepCheck_InvalidCurveOnSurface;
81 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface:
82 anErrStruct.error = BRepCheck_InvalidCurveOnClosedSurface;
84 case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag:
85 anErrStruct.error = BRepCheck_InvalidSameRangeFlag;
87 case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag:
88 anErrStruct.error = BRepCheck_InvalidSameParameterFlag;
90 case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag:
91 anErrStruct.error = BRepCheck_InvalidDegeneratedFlag;
93 case GEOM::GEOM_IMeasureOperations::FreeEdge:
94 anErrStruct.error = BRepCheck_FreeEdge;
96 case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity:
97 anErrStruct.error = BRepCheck_InvalidMultiConnexity;
99 case GEOM::GEOM_IMeasureOperations::InvalidRange:
100 anErrStruct.error = BRepCheck_InvalidRange;
102 case GEOM::GEOM_IMeasureOperations::EmptyWire:
103 anErrStruct.error = BRepCheck_EmptyWire;
105 case GEOM::GEOM_IMeasureOperations::RedundantEdge:
106 anErrStruct.error = BRepCheck_RedundantEdge;
108 case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire:
109 anErrStruct.error = BRepCheck_SelfIntersectingWire;
111 case GEOM::GEOM_IMeasureOperations::NoSurface:
112 anErrStruct.error = BRepCheck_NoSurface;
114 case GEOM::GEOM_IMeasureOperations::InvalidWire:
115 anErrStruct.error = BRepCheck_InvalidWire;
117 case GEOM::GEOM_IMeasureOperations::RedundantWire:
118 anErrStruct.error = BRepCheck_RedundantWire;
120 case GEOM::GEOM_IMeasureOperations::IntersectingWires:
121 anErrStruct.error = BRepCheck_IntersectingWires;
123 case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires:
124 anErrStruct.error = BRepCheck_InvalidImbricationOfWires;
126 case GEOM::GEOM_IMeasureOperations::EmptyShell:
127 anErrStruct.error = BRepCheck_EmptyShell;
129 case GEOM::GEOM_IMeasureOperations::RedundantFace:
130 anErrStruct.error = BRepCheck_RedundantFace;
132 case GEOM::GEOM_IMeasureOperations::UnorientableShape:
133 anErrStruct.error = BRepCheck_UnorientableShape;
135 case GEOM::GEOM_IMeasureOperations::NotClosed:
136 anErrStruct.error = BRepCheck_NotClosed;
138 case GEOM::GEOM_IMeasureOperations::NotConnected:
139 anErrStruct.error = BRepCheck_NotConnected;
141 case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape:
142 anErrStruct.error = BRepCheck_SubshapeNotInShape;
144 case GEOM::GEOM_IMeasureOperations::BadOrientation:
145 anErrStruct.error = BRepCheck_BadOrientation;
147 case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape:
148 anErrStruct.error = BRepCheck_BadOrientationOfSubshape;
150 case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue:
151 anErrStruct.error = BRepCheck_InvalidToleranceValue;
153 case GEOM::GEOM_IMeasureOperations::CheckFail:
154 anErrStruct.error = BRepCheck_CheckFail;
161 int aLen = anIncrims.length();
163 for (; ii < aLen; ii++) {
164 anErrStruct.incriminated.push_back(anIncrims[ii]);
167 theErrorsTo.push_back(anErrStruct);
172 * This function converts shape errors from theErrorsFrom to theErrorsTo.
173 * Note that theErrorsTo is not cleared at first.
175 * \param theErrorsFrom errors to be converted.
176 * \param theErrorsTo result errors.
178 static void ConvertShapeError
179 (const std::list<GEOMImpl_IMeasureOperations::ShapeError> &theErrorsFrom,
180 GEOM::GEOM_IMeasureOperations::ShapeErrors_out &theErrorsTo)
182 const int aNbErr = theErrorsFrom.size();
183 GEOM::GEOM_IMeasureOperations::ShapeErrors_var anErrArray =
184 new GEOM::GEOM_IMeasureOperations::ShapeErrors;
186 anErrArray->length(aNbErr);
188 // fill the local CORBA array with values from lists
189 std::list<GEOMImpl_IMeasureOperations::ShapeError>::const_iterator
190 anIt = theErrorsFrom.begin();
193 for (; anIt != theErrorsFrom.end(); i++, anIt++) {
194 GEOM::GEOM_IMeasureOperations::ShapeError_var anErrStruct =
195 new GEOM::GEOM_IMeasureOperations::ShapeError;
197 switch (anIt->error) {
198 case BRepCheck_InvalidPointOnCurve:
199 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve;
201 case BRepCheck_InvalidPointOnCurveOnSurface:
202 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface;
204 case BRepCheck_InvalidPointOnSurface:
205 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface;
207 case BRepCheck_No3DCurve:
208 anErrStruct->error = GEOM::GEOM_IMeasureOperations::No3DCurve;
210 case BRepCheck_Multiple3DCurve:
211 anErrStruct->error = GEOM::GEOM_IMeasureOperations::Multiple3DCurve;
213 case BRepCheck_Invalid3DCurve:
214 anErrStruct->error = GEOM::GEOM_IMeasureOperations::Invalid3DCurve;
216 case BRepCheck_NoCurveOnSurface:
217 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoCurveOnSurface;
219 case BRepCheck_InvalidCurveOnSurface:
220 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface;
222 case BRepCheck_InvalidCurveOnClosedSurface:
223 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface;
225 case BRepCheck_InvalidSameRangeFlag:
226 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag;
228 case BRepCheck_InvalidSameParameterFlag:
229 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag;
231 case BRepCheck_InvalidDegeneratedFlag:
232 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag;
234 case BRepCheck_FreeEdge:
235 anErrStruct->error = GEOM::GEOM_IMeasureOperations::FreeEdge;
237 case BRepCheck_InvalidMultiConnexity:
238 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity;
240 case BRepCheck_InvalidRange:
241 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidRange;
243 case BRepCheck_EmptyWire:
244 anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyWire;
246 case BRepCheck_RedundantEdge:
247 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantEdge;
249 case BRepCheck_SelfIntersectingWire:
250 anErrStruct->error = GEOM::GEOM_IMeasureOperations::SelfIntersectingWire;
252 case BRepCheck_NoSurface:
253 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoSurface;
255 case BRepCheck_InvalidWire:
256 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidWire;
258 case BRepCheck_RedundantWire:
259 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantWire;
261 case BRepCheck_IntersectingWires:
262 anErrStruct->error = GEOM::GEOM_IMeasureOperations::IntersectingWires;
264 case BRepCheck_InvalidImbricationOfWires:
265 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires;
267 case BRepCheck_EmptyShell:
268 anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyShell;
270 case BRepCheck_RedundantFace:
271 anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantFace;
273 case BRepCheck_UnorientableShape:
274 anErrStruct->error = GEOM::GEOM_IMeasureOperations::UnorientableShape;
276 case BRepCheck_NotClosed:
277 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotClosed;
279 case BRepCheck_NotConnected:
280 anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotConnected;
282 case BRepCheck_SubshapeNotInShape:
283 anErrStruct->error = GEOM::GEOM_IMeasureOperations::SubshapeNotInShape;
285 case BRepCheck_BadOrientation:
286 anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientation;
288 case BRepCheck_BadOrientationOfSubshape:
289 anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape;
291 case BRepCheck_InvalidToleranceValue:
292 anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidToleranceValue;
294 case BRepCheck_CheckFail:
295 anErrStruct->error = GEOM::GEOM_IMeasureOperations::CheckFail;
301 std::list<int> aIndList = anIt->incriminated;
302 GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
303 anIncrims->length(aIndList.size());
305 std::list<int>::iterator anIndIt = aIndList.begin();
308 for (; anIndIt != aIndList.end(); jj++, anIndIt++) {
309 anIncrims[jj] = *anIndIt;
312 anErrStruct->incriminated = anIncrims;
314 anErrArray[i] = anErrStruct;
317 // initialize out-parameter with local array
318 theErrorsTo = anErrArray._retn();
321 //=============================================================================
325 //=============================================================================
326 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
327 GEOM::GEOM_Gen_ptr theEngine,
328 ::GEOMImpl_IMeasureOperations* theImpl)
329 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
331 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
334 //=============================================================================
338 //=============================================================================
339 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
341 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
344 //=============================================================================
348 //=============================================================================
349 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
350 (GEOM::GEOM_Object_ptr theShape,
351 GEOM::ListOfLong_out theIntegers,
352 GEOM::ListOfDouble_out theDoubles)
354 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
356 // allocate the CORBA arrays
357 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
358 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
360 //Get the reference shape
361 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
363 if (!aShape.IsNull()) {
364 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
365 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
367 // Detect kind of shape and parameters
368 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
370 int nbInts = anIntegers->Length();
371 int nbDbls = aDoubles->Length();
373 anIntegersArray->length(nbInts);
374 aDoublesArray->length(nbDbls);
376 for (int ii = 0; ii < nbInts; ii++) {
377 anIntegersArray[ii] = anIntegers->Value(ii + 1);
379 for (int id = 0; id < nbDbls; id++) {
380 aDoublesArray[id] = aDoubles->Value(id + 1);
384 // initialize out-parameters with local arrays
385 theIntegers = anIntegersArray._retn();
386 theDoubles = aDoublesArray._retn();
387 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
390 //=============================================================================
394 //=============================================================================
395 void GEOM_IMeasureOperations_i::GetPosition
396 (GEOM::GEOM_Object_ptr theShape,
397 CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
398 CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
399 CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
401 //Set a not done flag
402 GetOperations()->SetNotDone();
404 //Set default values: global CS
405 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
408 //Get the reference shape
409 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
410 if (aShape.IsNull()) return;
412 // Get shape parameters
413 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
416 //=============================================================================
420 //=============================================================================
421 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
422 (GEOM::GEOM_Object_ptr theShape)
424 GEOM::GEOM_Object_var aGEOMObject;
426 //Set a not done flag
427 GetOperations()->SetNotDone();
429 //Get the reference shape
430 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
431 if (aShape.IsNull()) return aGEOMObject._retn();
433 // Make Point - centre of mass of theShape
434 Handle(::GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
435 if (!GetOperations()->IsDone() || anObject.IsNull())
436 return aGEOMObject._retn();
438 return GetObject(anObject);
441 //=============================================================================
445 //=============================================================================
446 GEOM::GEOM_Object_ptr
447 GEOM_IMeasureOperations_i::GetVertexByIndex( GEOM::GEOM_Object_ptr theShape,
448 CORBA::Long theIndex,
449 CORBA::Boolean theUseOri )
451 GEOM::GEOM_Object_var aGEOMObject;
453 //Set a not done flag
454 GetOperations()->SetNotDone();
456 //Get the reference shape
457 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
458 if ( aShape.IsNull() ) return aGEOMObject._retn();
460 // Get vertex by index
461 Handle(::GEOM_Object) anObject = GetOperations()->GetVertexByIndex(aShape, theIndex, theUseOri);
462 if (!GetOperations()->IsDone() || anObject.IsNull())
463 return aGEOMObject._retn();
465 return GetObject(anObject);
468 //=============================================================================
472 //=============================================================================
473 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetNormal
474 (GEOM::GEOM_Object_ptr theFace,
475 GEOM::GEOM_Object_ptr theOptionalPoint)
477 GEOM::GEOM_Object_var aGEOMObject;
479 //Set a not done flag
480 GetOperations()->SetNotDone();
482 //Get the reference shape
483 Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
484 if (aFace.IsNull()) return aGEOMObject._retn();
486 // Get the OptionalPoint (can be not defined)
487 Handle(::GEOM_Object) anOptionalPoint = GetObjectImpl(theOptionalPoint);
489 // Make Vector - normal to theFace (in point theOptionalPoint if the face is not planar)
490 Handle(::GEOM_Object) anObject = GetOperations()->GetNormal(aFace, anOptionalPoint);
491 if (!GetOperations()->IsDone() || anObject.IsNull())
492 return aGEOMObject._retn();
494 return GetObject(anObject);
497 //=============================================================================
501 //=============================================================================
502 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
503 CORBA::Double theTolerance,
504 CORBA::Double& theLength,
505 CORBA::Double& theSurfArea,
506 CORBA::Double& theVolume)
508 //Set a not done flag
509 GetOperations()->SetNotDone();
511 //Get the reference shape
512 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
513 if (aShape.IsNull()) return;
515 // Get shape parameters
516 GetOperations()->GetBasicProperties(aShape, theTolerance, theLength,
517 theSurfArea, theVolume);
520 //=============================================================================
524 //=============================================================================
525 void GEOM_IMeasureOperations_i::GetInertia
526 (GEOM::GEOM_Object_ptr theShape,
527 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
528 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
529 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
530 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
532 //Set a not done flag
533 GetOperations()->SetNotDone();
535 //Get the reference shape
536 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
537 if (aShape.IsNull()) return;
539 // Get shape parameters
540 GetOperations()->GetInertia(aShape,
547 //=============================================================================
551 //=============================================================================
552 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
553 CORBA::Boolean precise,
554 CORBA::Double& Xmin, CORBA::Double& Xmax,
555 CORBA::Double& Ymin, CORBA::Double& Ymax,
556 CORBA::Double& Zmin, CORBA::Double& Zmax)
558 //Set a not done flag
559 GetOperations()->SetNotDone();
561 //Get the reference shape
562 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
563 if (aShape.IsNull()) return;
565 // Get shape parameters
566 GetOperations()->GetBoundingBox
567 (aShape, precise, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
570 //=============================================================================
574 //=============================================================================
575 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::MakeBoundingBox
576 (GEOM::GEOM_Object_ptr theShape,
577 CORBA::Boolean precise)
579 GEOM::GEOM_Object_var aGEOMObject;
581 //Set a not done flag
582 GetOperations()->SetNotDone();
584 //Get the reference shape
585 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
586 if (aShape.IsNull()) return aGEOMObject._retn();
588 // Make Box - bounding box of theShape
589 Handle(::GEOM_Object) anObject =
590 GetOperations()->GetBoundingBox(aShape, precise);
591 if (!GetOperations()->IsDone() || anObject.IsNull())
592 return aGEOMObject._retn();
594 return GetObject(anObject);
597 //=============================================================================
601 //=============================================================================
602 void GEOM_IMeasureOperations_i::GetTolerance
603 (GEOM::GEOM_Object_ptr theShape,
604 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
605 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
606 CORBA::Double& VertMin, CORBA::Double& VertMax)
608 //Set a not done flag
609 GetOperations()->SetNotDone();
611 //Get the reference shape
612 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
613 if (aShape.IsNull()) return;
615 // Get shape parameters
616 GetOperations()->GetTolerance(aShape,
622 //=============================================================================
626 //=============================================================================
627 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape
628 (GEOM::GEOM_Object_ptr theShape,
629 GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
631 //Set a not done flag
632 GetOperations()->SetNotDone();
634 if (CORBA::is_nil(theShape))
639 //Get the reference shape
640 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
647 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
648 bool isOk = GetOperations()->CheckShape(aShape, false, anErrList);
650 ConvertShapeError(anErrList, theErrors);
655 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry
656 (GEOM::GEOM_Object_ptr theShape,
657 GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors)
659 //Set a not done flag
660 GetOperations()->SetNotDone();
662 if (CORBA::is_nil(theShape))
667 //Get the reference shape
668 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
675 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
676 bool isOk = GetOperations()->CheckShape(aShape, true, anErrList);
678 ConvertShapeError(anErrList, theErrors);
683 //=============================================================================
687 //=============================================================================
688 char* GEOM_IMeasureOperations_i::PrintShapeErrors
689 ( GEOM::GEOM_Object_ptr theShape,
690 const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors)
692 //Get the reference shape
693 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
697 GetOperations()->SetErrorCode(WRN_SHAPE_IS_NULL);
698 return CORBA::string_dup("");
701 // Convert the errors sequence
702 std::list<GEOMImpl_IMeasureOperations::ShapeError> anErrList;
704 ConvertShapeError(theErrors, anErrList);
706 TCollection_AsciiString aDescr =
707 GetOperations()->PrintShapeErrors(aShape, anErrList);
709 return CORBA::string_dup(aDescr.ToCString());
712 //=============================================================================
714 * CheckSelfIntersections
716 //=============================================================================
717 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape,
718 CORBA::Long theCheckLevel,
719 GEOM::ListOfLong_out theIntersections)
721 // Set a not done flag
722 GetOperations()->SetNotDone();
726 // Allocate the CORBA arrays
727 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
729 // Get the reference shape
730 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
732 if (!aShape.IsNull()) {
733 GEOMImpl_IMeasureOperations::SICheckLevel aCheckLevel;
735 switch(theCheckLevel) {
737 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_V;
740 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_E;
743 aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_E;
746 aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_F;
749 aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_F;
753 aCheckLevel = GEOMImpl_IMeasureOperations::SI_ALL;
757 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
759 // Detect self-intersections
760 isGood = GetOperations()->CheckSelfIntersections
761 (aShape, aCheckLevel, anIntegers);
763 int nbInts = anIntegers->Length();
765 anIntegersArray->length(nbInts);
767 for (int ii = 0; ii < nbInts; ii++) {
768 anIntegersArray[ii] = anIntegers->Value(ii + 1);
772 // Initialize out-parameters with local arrays
773 theIntersections = anIntegersArray._retn();
777 //=============================================================================
779 * CheckSelfIntersectionsFast
781 //=============================================================================
782 CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersectionsFast
783 (GEOM::GEOM_Object_ptr theShape,
784 CORBA::Float theDeflection,
785 CORBA::Double theTolerance,
786 GEOM::ListOfLong_out theIntersections)
788 // Set a not done flag
789 GetOperations()->SetNotDone();
793 // Allocate the CORBA arrays
794 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
796 // Get the reference shape
797 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
799 if (!aShape.IsNull()) {
800 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
802 // Detect self-intersections
803 isGood = GetOperations()->CheckSelfIntersectionsFast
804 (aShape, theDeflection, theTolerance, anIntegers);
806 int nbInts = anIntegers->Length();
808 anIntegersArray->length(nbInts);
810 for (int ii = 0; ii < nbInts; ii++) {
811 anIntegersArray[ii] = anIntegers->Value(ii + 1);
815 // Initialize out-parameters with local arrays
816 theIntersections = anIntegersArray._retn();
820 //=============================================================================
824 //=============================================================================
825 CORBA::Boolean GEOM_IMeasureOperations_i::CheckBOPArguments
826 (GEOM::GEOM_Object_ptr theShape)
828 // Set a not done flag
829 GetOperations()->SetNotDone();
831 // Get the reference shape
832 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
835 if (!aShape.IsNull()) {
836 // Check BOP arguments
837 isGood = GetOperations()->CheckBOPArguments(aShape);
843 //=============================================================================
847 //=============================================================================
848 CORBA::Boolean GEOM_IMeasureOperations_i::FastIntersect (GEOM::GEOM_Object_ptr theShape1,
849 GEOM::GEOM_Object_ptr theShape2,
850 CORBA::Double theTolerance,
851 CORBA::Float theDeflection,
852 GEOM::ListOfLong_out theIntersections1,
853 GEOM::ListOfLong_out theIntersections2)
855 // Set a not done flag
856 GetOperations()->SetNotDone();
860 // Allocate the CORBA arrays
861 GEOM::ListOfLong_var anIntegersArray1 = new GEOM::ListOfLong();
862 GEOM::ListOfLong_var anIntegersArray2 = new GEOM::ListOfLong();
864 // Get the reference shape
865 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
866 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
868 if (!aShape1.IsNull() && !aShape2.IsNull()) {
869 Handle(TColStd_HSequenceOfInteger) anIntegers1 = new TColStd_HSequenceOfInteger;
870 Handle(TColStd_HSequenceOfInteger) anIntegers2 = new TColStd_HSequenceOfInteger;
872 // Detect intersections
873 isGood = GetOperations()->FastIntersect
874 (aShape1, aShape2, theTolerance, theDeflection, anIntegers1, anIntegers2);
876 int nbInts1 = anIntegers1->Length();
877 int nbInts2 = anIntegers2->Length();
879 anIntegersArray1->length(nbInts1);
880 anIntegersArray2->length(nbInts2);
882 for (int ii = 0; ii < nbInts1; ii++) {
883 anIntegersArray1[ii] = anIntegers1->Value(ii + 1);
885 for (int ii = 0; ii < nbInts2; ii++) {
886 anIntegersArray2[ii] = anIntegers2->Value(ii + 1);
890 // Initialize out-parameters with local arrays
891 theIntersections1 = anIntegersArray1._retn();
892 theIntersections2 = anIntegersArray2._retn();
896 //=============================================================================
900 //=============================================================================
901 char* GEOM_IMeasureOperations_i::IsGoodForSolid (GEOM::GEOM_Object_ptr theShape)
903 //Set a not done flag
904 GetOperations()->SetNotDone();
906 //Get the reference shape
907 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
908 if (aShape.IsNull()) return CORBA::string_dup("WRN_NULL_OBJECT_OR_SHAPE");
910 // Get shape parameters
911 TCollection_AsciiString aDescription = GetOperations()->IsGoodForSolid(aShape);
912 return CORBA::string_dup(aDescription.ToCString());
915 //=============================================================================
919 //=============================================================================
920 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
922 //Set a not done flag
923 GetOperations()->SetNotDone();
925 //Get the reference shape
926 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
929 //Assume the "WhatIs" operation as being done
930 GetOperations()->SetErrorCode(OK);
931 return CORBA::string_dup(WRN_SHAPE_IS_NULL);
934 // Get shape parameters
935 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
936 return CORBA::string_dup(aDescription.ToCString());
939 //=============================================================================
943 //=============================================================================
944 GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
945 const GEOM::ListOfDouble& theCoords,
946 CORBA::Double tolerance)
948 //Set a not done flag
949 GetOperations()->SetNotDone();
951 int nb_points = theCoords.length()/3;
953 GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
954 aResults->length(nb_points);
956 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
958 std::vector<double> tmp(3*nb_points);
959 for (int i = 0; i < 3*nb_points; i++)
960 tmp[i] = theCoords[i];
961 std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
962 for (int i = 0, resSize = res.size(); i < nb_points; i++)
963 aResults[i] = i < resSize ? res[i] : false;
964 return aResults._retn();
967 //=============================================================================
971 //=============================================================================
972 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
973 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
974 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
975 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
977 //Set a not done flag
978 GetOperations()->SetNotDone();
980 //Get the reference shape
981 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
982 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
983 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
985 // Get shape parameters
986 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
989 //=============================================================================
993 //=============================================================================
994 CORBA::Long GEOM_IMeasureOperations_i::ClosestPoints
995 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
996 GEOM::ListOfDouble_out theCoords)
998 //Set a not done flag
999 GetOperations()->SetNotDone();
1001 // allocate the CORBA array
1003 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
1005 //Get the reference shape
1006 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1007 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1009 if (!aShape1.IsNull() && !aShape2.IsNull()) {
1010 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
1011 // Get shape parameters
1012 nbSols = GetOperations()->ClosestPoints(aShape1, aShape2, aDoubles);
1013 int nbDbls = aDoubles->Length();
1014 aDoublesArray->length(nbDbls);
1015 for (int id = 0; id < nbDbls; id++) {
1016 aDoublesArray[id] = aDoubles->Value(id + 1);
1020 theCoords = aDoublesArray._retn();
1024 //=============================================================================
1028 //=============================================================================
1029 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
1030 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
1033 //Set a not done flag
1034 GetOperations()->SetNotDone();
1036 //Get the reference shape
1037 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1038 if (aShape.IsNull())
1041 // Get shape parameters
1042 GetOperations()->PointCoordinates( aShape, X, Y, Z );
1045 //=============================================================================
1049 //=============================================================================
1050 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
1051 GEOM::GEOM_Object_ptr theShape2)
1053 //Set a not done flag
1054 GetOperations()->SetNotDone();
1056 //Get the reference shapes
1057 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1058 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1059 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1062 return GetOperations()->GetAngle(aShape1, aShape2);
1065 //=============================================================================
1069 //=============================================================================
1070 CORBA::Double GEOM_IMeasureOperations_i::GetAngleBtwVectors (GEOM::GEOM_Object_ptr theShape1,
1071 GEOM::GEOM_Object_ptr theShape2)
1073 //Set a not done flag
1074 GetOperations()->SetNotDone();
1076 //Get the reference shapes
1077 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1078 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1079 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
1082 return GetOperations()->GetAngleBtwVectors(aShape1, aShape2);
1085 //=============================================================================
1089 //=============================================================================
1090 GEOM::ListOfGO* GEOM_IMeasureOperations_i::PatchFace(GEOM::GEOM_Object_ptr theShape)
1092 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1094 //Get the reference shape
1095 Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1096 if (aShapeRef.IsNull()) return aSeq._retn();
1098 // Perform patch face operation
1099 Handle(TColStd_HSequenceOfTransient) aHSeq =
1100 GetOperations()->PatchFace(aShapeRef);
1101 if (!GetOperations()->IsDone() || aHSeq.IsNull())
1102 return aSeq._retn();
1104 Standard_Integer aLength = aHSeq->Length();
1105 aSeq->length(aLength);
1106 for (Standard_Integer i = 1; i <= aLength; i++)
1107 aSeq[i - 1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1109 return aSeq._retn();
1112 //=============================================================================
1114 * CurveCurvatureByParam
1116 //=============================================================================
1117 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByParam
1118 (GEOM::GEOM_Object_ptr theCurve, CORBA::Double theParam)
1120 //Set a not done flag
1121 GetOperations()->SetNotDone();
1123 //Get the reference shape
1124 Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1125 if(aShape.IsNull()) return -1.0;
1127 return GetOperations()->CurveCurvatureByParam(aShape,theParam);
1130 //=============================================================================
1132 * CurveCurvatureByPoint
1134 //=============================================================================
1135 CORBA::Double GEOM_IMeasureOperations_i::CurveCurvatureByPoint
1136 (GEOM::GEOM_Object_ptr theCurve, GEOM::GEOM_Object_ptr thePoint)
1138 //Set a not done flag
1139 GetOperations()->SetNotDone();
1141 //Get the reference shape
1142 Handle(::GEOM_Object) aShape = GetObjectImpl(theCurve);
1143 Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1144 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1146 return GetOperations()->CurveCurvatureByPoint(aShape,aPoint);
1150 //=============================================================================
1152 * MaxSurfaceCurvatureByParam
1154 //=============================================================================
1155 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByParam
1156 (GEOM::GEOM_Object_ptr theSurf,
1157 CORBA::Double theUParam,
1158 CORBA::Double theVParam)
1160 //Set a not done flag
1161 GetOperations()->SetNotDone();
1163 //Get the reference shape
1164 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1165 if(aShape.IsNull()) return -1.0;
1167 return GetOperations()->MaxSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1170 //=============================================================================
1172 * MaxSurfaceCurvatureByPoint
1174 //=============================================================================
1175 CORBA::Double GEOM_IMeasureOperations_i::MaxSurfaceCurvatureByPoint
1176 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1178 //Set a not done flag
1179 GetOperations()->SetNotDone();
1181 //Get the reference shape
1182 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1183 Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1184 if( aShape.IsNull() || aPoint.IsNull() ) return -1.0;
1186 return GetOperations()->MaxSurfaceCurvatureByPoint(aShape,aPoint);
1189 //=============================================================================
1191 * MinSurfaceCurvatureByParam
1193 //=============================================================================
1194 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByParam
1195 (GEOM::GEOM_Object_ptr theSurf,
1196 CORBA::Double theUParam,
1197 CORBA::Double theVParam)
1199 //Set a not done flag
1200 GetOperations()->SetNotDone();
1202 //Get the reference shape
1203 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1204 if (aShape.IsNull()) return -1.0;
1206 return GetOperations()->MinSurfaceCurvatureByParam(aShape,theUParam,theVParam);
1209 //=============================================================================
1211 * MinSurfaceCurvatureByPoint
1213 //=============================================================================
1214 CORBA::Double GEOM_IMeasureOperations_i::MinSurfaceCurvatureByPoint
1215 (GEOM::GEOM_Object_ptr theSurf, GEOM::GEOM_Object_ptr thePoint)
1217 //Set a not done flag
1218 GetOperations()->SetNotDone();
1220 //Get the reference shape
1221 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1222 Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1223 if (aShape.IsNull() || aPoint.IsNull()) return -1.0;
1225 return GetOperations()->MinSurfaceCurvatureByPoint(aShape,aPoint);
1228 //=============================================================================
1230 * SurfaceCurvatureByPointAndDirection
1232 //=============================================================================
1233 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::SurfaceCurvatureByPointAndDirection
1234 (GEOM::GEOM_Object_ptr theSurf,
1235 GEOM::GEOM_Object_ptr thePoint,
1236 GEOM::GEOM_Object_ptr theDirection)
1238 GEOM::GEOM_Object_var aGEOMObject;
1240 //Set a not done flag
1241 GetOperations()->SetNotDone();
1243 //Get the reference shape
1244 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1245 Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
1246 Handle(::GEOM_Object) aDirection = GetObjectImpl(theDirection);
1247 if (aShape.IsNull() || aPoint.IsNull() || aDirection.IsNull()) return aGEOMObject._retn();
1249 Handle(::GEOM_Object) anObject =
1250 GetOperations()->SurfaceCurvatureByPointAndDirection(aShape,aPoint,aDirection);
1251 if (!GetOperations()->IsDone() || anObject.IsNull())
1252 return aGEOMObject._retn();
1254 return GetObject(anObject);
1257 //=============================================================================
1261 //=============================================================================
1262 GEOM::ListOfDouble* GEOM_IMeasureOperations_i::XYZtoUV
1263 (GEOM::GEOM_Object_ptr theSurf,
1264 const GEOM::ListOfDouble& theXYZlist,
1265 CORBA::Boolean theIsNormalized)
1267 GEOM::ListOfDouble_var resUV = new GEOM::ListOfDouble;
1269 //Set a not done flag
1270 GetOperations()->SetNotDone();
1272 //Get the reference shape
1273 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1274 if (aShape.IsNull()) return resUV._retn();
1276 //Get input XYZ list
1277 Handle(TColStd_HArray1OfReal) aXYZlist =
1278 new TColStd_HArray1OfReal (0, theXYZlist.length() - 1);
1280 size_t nb = theXYZlist.length();
1281 for (size_t i = 0; i < nb; ++i)
1282 aXYZlist->SetValue(i, theXYZlist[i]);
1285 //Call implementation
1286 Handle(TColStd_HArray1OfReal) aUVlist =
1287 GetOperations()->XYZtoUV(aShape, aXYZlist, theIsNormalized);
1289 if (GetOperations()->IsDone()) {
1290 resUV->length(aUVlist->Length());
1291 int i0 = aUVlist->Lower();
1292 int nb = aUVlist->Upper();
1293 for (int i = i0; i <= nb; ++i)
1294 resUV[ i-i0 ] = aUVlist->Value(i);
1297 return resUV._retn();
1300 //=============================================================================
1304 //=============================================================================
1305 GEOM::ListOfDouble* GEOM_IMeasureOperations_i::UVtoXYZ
1306 (GEOM::GEOM_Object_ptr theSurf,
1307 const GEOM::ListOfDouble& theUVlist,
1308 CORBA::Boolean theIsNormalized)
1310 GEOM::ListOfDouble_var resXYZ = new GEOM::ListOfDouble;
1312 //Set a not done flag
1313 GetOperations()->SetNotDone();
1315 //Get the reference shape
1316 Handle(::GEOM_Object) aShape = GetObjectImpl(theSurf);
1317 if (aShape.IsNull()) return resXYZ._retn();
1320 Handle(TColStd_HArray1OfReal) aUVlist =
1321 new TColStd_HArray1OfReal (0, theUVlist.length() - 1);
1323 size_t nb = theUVlist.length();
1324 for (size_t i = 0; i < nb; ++i)
1325 aUVlist->SetValue(i, theUVlist[i]);
1328 //Call implementation
1329 Handle(TColStd_HArray1OfReal) aXYZlist =
1330 GetOperations()->UVtoXYZ(aShape, aUVlist, theIsNormalized);
1332 if (GetOperations()->IsDone()) {
1333 resXYZ->length(aXYZlist->Length());
1334 int i0 = aXYZlist->Lower();
1335 int nb = aXYZlist->Upper();
1336 for (int i = i0; i <= nb; ++i)
1337 resXYZ[ i-i0 ] = aXYZlist->Value(i);
1340 return resXYZ._retn();
1343 //=============================================================================
1346 * Find all self-intersected 2D curves.
1347 * \param theShape Shape for check.
1349 //=============================================================================
1350 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::SelfIntersected2D(
1351 const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts)
1353 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1354 new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1356 // Perform patch face operation
1357 std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1358 ConvertToList(theResuts, aResults);
1360 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aSelfInters = GetOperations()->SelfIntersected2D(aResults);
1361 if (!GetOperations()->IsDone() || aSelfInters.empty())
1362 return aSeq._retn();
1364 Standard_Integer aLength = aSelfInters.size();
1365 aSeq->length(aLength);
1366 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aSelfInters.begin());
1367 for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1369 aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1370 aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1373 return aSeq._retn();
1376 //=============================================================================
1378 * InterferingSubshapes
1379 * Find pairs of interfering sub-shapes, by default all pairs of interfering shapes are returned.
1380 * \param theShape Shape for check.
1381 * \param theShapeType1 Type of shape.
1382 * \param theShapeType2 Type of shape.
1384 //=============================================================================
1385 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::InterferingSubshapes(
1386 const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1387 const CORBA::Long theShapeType1,
1388 const CORBA::Long theShapeType2)
1390 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1391 new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1393 // Perform patch face operation
1394 std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1395 ConvertToList(theResuts, aResults);
1397 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aSelfInterf =
1398 GetOperations()->InterferingSubshapes(aResults, theShapeType1, theShapeType2);
1399 if (!GetOperations()->IsDone() || aSelfInterf.empty())
1400 return aSeq._retn();
1402 Standard_Integer aLength = aSelfInterf.size();
1403 aSeq->length(aLength);
1404 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aSelfInterf.begin());
1405 for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1407 aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1408 aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1411 return aSeq._retn();
1414 //=============================================================================
1417 * Find edges, which are fully covered by tolerances of vertices.
1418 * \param theShape Shape for check.
1420 //=============================================================================
1421 GEOM::ListOfGO* GEOM_IMeasureOperations_i::SmallEdges(const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts)
1423 GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1425 std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1426 ConvertToList(theResuts, aResults);
1428 //Get the reference shape
1429 Handle(TColStd_HSequenceOfTransient) aSmallEdges = GetOperations()->SmallEdges(aResults);
1430 if (!GetOperations()->IsDone() || aSmallEdges.IsNull())
1431 return aSeq._retn();
1433 Standard_Integer aLength = aSmallEdges->Length();
1434 aSeq->length(aLength);
1435 for (Standard_Integer i = 1; i <= aLength; i++)
1436 aSeq[i - 1] = GetObject(Handle(::GEOM_Object)::DownCast(aSmallEdges->Value(i)));
1438 return aSeq._retn();
1441 //=============================================================================
1444 * find remote objects (sub-shape on a shape).
1445 * \param theShape Shape for check.
1446 * \param theShapeType Type of shape.
1447 * \param theSubShapeType Type of sub-shape.
1448 * \param theTolerance tolerance.
1450 //=============================================================================
1451 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape* GEOM_IMeasureOperations_i::DistantShapes(
1452 const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1453 const CORBA::Long theShapeType,
1454 const CORBA::Long theSubShapeType,
1455 const CORBA::Double theTolerance)
1457 GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape_var aSeq =
1458 new GEOM::GEOM_IMeasureOperations::SequenceOfPairOfShape;
1460 std::list<GEOMImpl_IMeasureOperations::FailedChecks> aResults;
1461 ConvertToList(theResuts, aResults);
1463 // Perform patch face operation
1464 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects> aDistantS =
1465 GetOperations()->DistantShapes(aResults, theShapeType, theSubShapeType, theTolerance);
1466 if (!GetOperations()->IsDone() || aDistantS.empty())
1467 return aSeq._retn();
1469 Standard_Integer aLength = aDistantS.size();
1470 aSeq->length(aLength);
1471 std::list<GEOMImpl_IMeasureOperations::CoupleOfObjects>::iterator anIter(aDistantS.begin());
1472 for (Standard_Integer i = 0; i < aLength; i++, ++anIter)
1474 aSeq[i].first = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).first));
1475 aSeq[i].second = GetObject(Handle(::GEOM_Object)::DownCast((*anIter).second));
1478 return aSeq._retn();
1481 //=============================================================================
1483 * CheckConformityShape
1484 * Perform all required checks
1486 //=============================================================================
1487 GEOM::GEOM_IMeasureOperations::CheckResults* GEOM_IMeasureOperations_i::CheckConformityShape(
1488 GEOM::GEOM_Object_ptr theShape)
1490 GEOM::GEOM_IMeasureOperations::CheckResults_var aRes = new GEOM::GEOM_IMeasureOperations::CheckResults;
1492 //Get the reference shape
1493 Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1494 if (aShapeRef.IsNull()) return nullptr;
1496 std::list<GEOMImpl_IMeasureOperations::FailedChecks> aChecks;
1497 GetOperations()->CheckConformityShape(aShapeRef, aChecks);
1499 Standard_Integer aLength = aChecks.size();
1500 aRes->length(aLength);
1501 std::list<GEOMImpl_IMeasureOperations::FailedChecks>::const_iterator anIntIt = aChecks.cbegin();
1502 for (Standard_Integer i = 0; i < aLength; i++, ++anIntIt)
1504 aRes[i].type = (*anIntIt).TypeOfCheck;
1505 aRes[i].failedShapes.first = GetObject(Handle(::GEOM_Object)::DownCast((*anIntIt).FailedShapes.first));
1506 aRes[i].failedShapes.second = GetObject(Handle(::GEOM_Object)::DownCast((*anIntIt).FailedShapes.second));
1509 return aRes._retn();
1512 //=============================================================================
1515 * Compute possible tolerance for the shape, minimize tolerance of shape as well
1516 * as tolerance of sub-shapes as much as possible
1517 * \param theShape Shape for check.
1519 //=============================================================================
1520 CORBA::Double GEOM_IMeasureOperations_i::UpdateTolerance(GEOM::GEOM_Object_ptr theShape)
1522 //Get the reference shape
1523 Handle(::GEOM_Object) aShapeRef = GetObjectImpl(theShape);
1524 if (aShapeRef.IsNull())
1527 return GetOperations()->UpdateTolerance(aShapeRef);
1530 void GEOM_IMeasureOperations_i::ConvertToList(const GEOM::GEOM_IMeasureOperations::CheckResults& theResuts,
1531 std::list<GEOMImpl_IMeasureOperations::FailedChecks>& theListOfResults)
1533 for (Standard_Integer i = 0; i < theResuts.length(); ++i)
1535 GEOMImpl_IMeasureOperations::FailedChecks aCheck;
1536 aCheck.TypeOfCheck = theResuts[i].type;
1537 aCheck.FailedShapes.first = GetObjectImpl(theResuts[i].failedShapes.first);
1538 aCheck.FailedShapes.second = GetObjectImpl(theResuts[i].failedShapes.second);
1539 theListOfResults.push_back(aCheck);
1543 //=============================================================================
1545 * ShapeProximityCalculator
1547 //=============================================================================
1548 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::ShapeProximityCalculator(GEOM::GEOM_Object_ptr theShape1,
1549 GEOM::GEOM_Object_ptr theShape2)
1551 GEOM::GEOM_Object_var anEmptyCalc;
1553 //Set a not done flag
1554 GetOperations()->SetNotDone();
1556 //Get the reference shape
1557 Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1);
1558 Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2);
1559 if (aShape1.IsNull() || aShape2.IsNull())
1560 return anEmptyCalc._retn();
1562 Handle(::GEOM_Object) aCalculator = GetOperations()->ShapeProximityCalculator(aShape1, aShape2);
1563 if (!GetOperations()->IsDone() || aCalculator.IsNull())
1564 return anEmptyCalc._retn();
1566 return GetObject(aCalculator);
1569 //=============================================================================
1573 //=============================================================================
1574 void GEOM_IMeasureOperations_i::SetShapeSampling(GEOM::GEOM_Object_ptr theCalculator,
1575 GEOM::GEOM_Object_ptr theShape,
1576 CORBA::Long theNbSamples)
1578 //Set a not done flag
1579 GetOperations()->SetNotDone();
1581 //Get the proximity calculator
1582 Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1585 //Get the reference shape
1586 Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1587 if (aShape.IsNull())
1590 GetOperations()->SetShapeSampling(aCalc, aShape, theNbSamples);
1593 //=============================================================================
1595 * GetCoarseProximity
1597 //=============================================================================
1598 CORBA::Double GEOM_IMeasureOperations_i::GetCoarseProximity(GEOM::GEOM_Object_ptr theCalculator)
1600 //Set a not done flag
1601 GetOperations()->SetNotDone();
1603 //Get the reference shape
1604 Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1608 Standard_Real aProximity = GetOperations()->GetCoarseProximity(aCalc);
1609 if (!GetOperations()->IsDone())
1615 //=============================================================================
1617 * GetPreciseProximity
1619 //=============================================================================
1620 CORBA::Double GEOM_IMeasureOperations_i::GetPreciseProximity(GEOM::GEOM_Object_ptr theCalculator)
1622 //Set a not done flag
1623 GetOperations()->SetNotDone();
1625 //Get the reference shape
1626 Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator);
1630 Standard_Real aProximity = GetOperations()->GetPreciseProximity(aCalc);
1631 if (!GetOperations()->IsDone())