From e3c9efb4736cffbdf4a1777a4b45e76732302437 Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 19 Nov 2024 21:50:50 +0000 Subject: [PATCH] Add Partition result to output --- idl/GEOM_Gen.idl | 4 +- src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx | 48 ++++++++++++++++---- src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx | 15 +++--- src/GEOMImpl/GEOMImpl_PartitionDriver.cxx | 3 ++ src/GEOMImpl/GEOMImpl_Types.hxx | 1 + src/GEOM_I/GEOM_IMeasureOperations_i.cc | 16 +++++-- src/GEOM_I/GEOM_IMeasureOperations_i.hh | 1 + src/GEOM_SWIG/geomBuilder.py | 19 ++++++-- 8 files changed, 85 insertions(+), 22 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index d4d2eed32..d5ca6c227 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -4805,7 +4805,8 @@ module GEOM // * \param theShortReport Whether to display the error report in short format // * \param theRunParallel Whether to run the computations in parallel // * \param theDoExact Whether to perform exact checking - // * \param theErrors Structure, containing discovered errors and incriminated sub-shapes. + // * \param theResultShape Output parameter. The result of BOP General Fuse. Indices of its sub-shapes are reported in theErrors structure. + // * \param theErrors Output parameter. Structure, containing discovered errors and incriminated sub-shapes. // * \return TRUE, if the input shapes "seem to be valid" for BOP. // */ boolean ExtractBOPFailure (in ListOfGO theShapes, @@ -4814,6 +4815,7 @@ module GEOM in boolean theShortReport, in boolean theRunParallel, in boolean theDoExact, + out GEOM_Object theResultShape, out ShapeErrors theErrors); /*! diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 11c27b534..2e8274b20 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -34,6 +34,9 @@ #include #include +#include +#include + #include #include @@ -1724,13 +1727,14 @@ TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors */ //============================================================================= bool GEOMImpl_IMeasureOperations::ExtractBOPFailure - (const Handle(TColStd_HSequenceOfTransient)& theShapes, - const bool theUseTimer, - const bool theTopoOnly, - const bool theShortReport, - const bool theRunParallel, - const bool theDoExact, - std::list& theErrors) + (const Handle(TColStd_HSequenceOfTransient)& theShapes, + const bool theUseTimer, + const bool theTopoOnly, + const bool theShortReport, + const bool theRunParallel, + const bool theDoExact, + Handle(GEOM_Object)& theResultShape, + std::list& theErrors) { SetErrorCode(KO); theErrors.clear(); @@ -1740,8 +1744,16 @@ bool GEOMImpl_IMeasureOperations::ExtractBOPFailure Standard_Integer aNbShapes = theShapes->Length(); if (!aNbShapes) return false; + // Create Partition object + theResultShape = GetEngine()->AddObject(GEOM_PARTITION); + Handle(GEOM_Function) aFunction = theResultShape->AddFunction + (GEOMImpl_PartitionDriver::GetID(), PARTITION_GENERAL_FUSE); + // For creation information filling + GEOMImpl_IPartition aCI (aFunction); + Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient; + TopTools_ListOfShape aList; - for (int i=1; i<=aNbShapes; i++) { + for (int i = 1; i <= aNbShapes; i++) { Handle(GEOM_Object) aGeomObj = Handle(GEOM_Object)::DownCast(theShapes->Value(i)); if (aGeomObj.IsNull()) continue; @@ -1754,9 +1766,12 @@ bool GEOMImpl_IMeasureOperations::ExtractBOPFailure if (aShape.IsNull()) continue; + aShapesSeq->Append(aRefShape); aList.Append(aShape); } + aCI.SetShapes(aShapesSeq); + // Call the GeomAnaTool API to extract BOP failures // TopTools_ListOfShape aFailuresList = GeomAnaTool::ExtractBOPFailure(aList, theUseTimer, theTopoOnly, theShortReport, theRunParallel, theDoExact); // std::cout << "ExtractBOPFailure: " << aFailuresList.Extent() << " failures" << std::endl; @@ -1773,6 +1788,12 @@ bool GEOMImpl_IMeasureOperations::ExtractBOPFailure aTool.SetRunParallel(theRunParallel); aTool.SetExactCheck(theDoExact); aTool.Perform(); + + // Set General Fuse result right here + // (without driver execution, as we already have the result shape) + TopoDS_Shape aShapeRes = aTool.Result(); + aFunction->SetValue(aShapeRes); + if (aTool.HasFailures()) { std::cout << "--- The operation has failures ---" << std::endl; @@ -1793,6 +1814,17 @@ bool GEOMImpl_IMeasureOperations::ExtractBOPFailure std::cout << "+++ The operation has no failures +++" << std::endl; isValid = true; } + + //Make a Python command + GEOM::TPythonDump aPD (aFunction); + aPD << "(isBOPFailure, " << theResultShape + << ", anErrors) = geompy.ExtractBOPFailure(["; + for (int i = 1; i <= aNbShapes; i++) { + aPD << Handle(GEOM_Object)::DownCast(theShapes->Value(i)); + if (i < aNbShapes) aPD << ", "; + } + aPD << "], " << theUseTimer << ", " << theTopoOnly << ", " << theShortReport + << ", " << theRunParallel << ", " << theDoExact << ")"; } catch(Standard_Failure& aFail) { diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index 8b677de56..d6eea1e27 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -163,13 +163,14 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { const std::list &theErrors); Standard_EXPORT bool ExtractBOPFailure - (const Handle(TColStd_HSequenceOfTransient)& theShapes, - const bool theUseTimer, - const bool theTopoOnly, - const bool theShortReport, - const bool theRunParallel, - const bool theDoExact, - std::list& theErrors); + (const Handle(TColStd_HSequenceOfTransient)& theShapes, + const bool theUseTimer, + const bool theTopoOnly, + const bool theShortReport, + const bool theRunParallel, + const bool theDoExact, + Handle(GEOM_Object)& theResultShape, + std::list& theErrors); Standard_EXPORT bool CheckSelfIntersections (Handle(GEOM_Object) theShape, const SICheckLevel theCheckLevel, diff --git a/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx b/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx index 9bee2250f..b90dae0c5 100644 --- a/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_PartitionDriver.cxx @@ -564,6 +564,9 @@ GetCreationInformation(std::string& theOperationName, AddParam( theParams, "Object", aCI.GetShape() ); AddParam( theParams, "Plane", aCI.GetPlane() ); break; + case PARTITION_GENERAL_FUSE: + AddParam( theParams, "Objects", aCI.GetShapes() ); + break; default: return false; } diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 9a0c75e65..044abaf85 100644 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -268,6 +268,7 @@ #define PARTITION_PARTITION 1 #define PARTITION_HALF 2 #define PARTITION_NO_SELF_INTERSECTIONS 3 +#define PARTITION_GENERAL_FUSE 4 #define POLYLINE_POINTS 1 #define POLYLINE2D_PLN_COORDS 2 diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index 1feb907c8..1eedcf699 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -722,8 +722,12 @@ CORBA::Boolean GEOM_IMeasureOperations_i::ExtractBOPFailure CORBA::Boolean theShortReport, CORBA::Boolean theRunParallel, CORBA::Boolean theDoExact, + GEOM::GEOM_Object_out theResultShape, GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors) { + GEOM::GEOM_Object_var aNullRes; + theResultShape = aNullRes._retn(); + // Set the not done flag GetOperations()->SetNotDone(); @@ -752,10 +756,16 @@ CORBA::Boolean GEOM_IMeasureOperations_i::ExtractBOPFailure } // Perform partition operation and check for failures + Handle(::GEOM_Object) aResultShape; std::list anErrList; - bool isOk = GetOperations()->ExtractBOPFailure(aSeqShapes, theUseTimer, theTopoOnly, - theShortReport, theRunParallel, theDoExact, - anErrList); + bool isOk = GetOperations()->ExtractBOPFailure + (aSeqShapes, theUseTimer, theTopoOnly, + theShortReport, theRunParallel, theDoExact, + aResultShape, anErrList); + + if (!aResultShape.IsNull()) { + theResultShape = GetObject(aResultShape); + } ConvertShapeError(anErrList, theErrors); diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index 3b346e796..ed6911efd 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -105,6 +105,7 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i : CORBA::Boolean theShortReport, CORBA::Boolean theRunParallel, CORBA::Boolean theDoExact, + GEOM::GEOM_Object_out theResultShape, GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors); CORBA::Boolean CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape, diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index 04cad8817..a553547cd 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -11983,10 +11983,21 @@ class geomBuilder(GEOM._objref_GEOM_Gen): return self.MeasuOp.CheckBOPArguments(theShape) + ## Extracts the BOP failure information from the given list of faces. + # @param lFaces - list of faces to extract the BOP failure information from. + # @param timer - if True, the time of the operation is measured. + # @param topo - if True, only the topological entities will be checked. + # @param short - if True, the error report will be in short format. + # @param parallel - if True, the operation will be executed in parallel. + # @param exact - if True, an exact check will be performed. + # @return (isValid, shapeResult, listOfErrors), where + # isValid - a boolean value (if result shape is valid or not), + # shapeResult - the result shape itself as GEOM::Object, + # listOfErrors - the list of GEOM.GEOM_IMeasureOperations.ShapeError. def ExtractBOPFailure(self, lFaces, timer=None, topo=None, short=None, parallel=None, exact=None): """ Extracts the BOP failure information from the given list of faces. - + Parameters: lFaces - list of faces to extract the BOP failure information from. timer - if True, the time of the operation is measured. @@ -11994,9 +12005,11 @@ class geomBuilder(GEOM._objref_GEOM_Gen): short - if True, the error report will be in short format. parallel - if True, the operation will be executed in parallel. exact - if True, an exact check will be performed. - + Returns: - the list of failed shapes. + a boolean value (if result shape is valid or not), + the result shape itself, + the list of GEOM.GEOM_IMeasureOperations.ShapeError. """ # Check for default parameter values if timer is None: -- 2.39.2