From: skv Date: Fri, 18 Dec 2015 14:30:19 +0000 (+0300) Subject: Statistics of the operation X-Git-Url: http://git.salome-platform.org/gitweb/?p=plugins%2Fcanrecplugin.git;a=commitdiff_plain;h=6b4b2b09efa11c7596b665771c90490c13fb4a9a Statistics of the operation --- diff --git a/doc/salome/examples/canrecplugindemo.py b/doc/salome/examples/canrecplugindemo.py index c88ff1e..82b5541 100644 --- a/doc/salome/examples/canrecplugindemo.py +++ b/doc/salome/examples/canrecplugindemo.py @@ -13,6 +13,13 @@ shape_igs = geompy.ImportIGES(path) # Build Canonical Recognition shape_cr = geompy.MakeCanonicalRecognition(shape_igs, True, True, 0.01) +# Get the number of canonical faces +init_nb_f = geompy.GetNbCanonicalFaces(shape_igs) +res_nb_f = geompy.GetNbCanonicalFaces(shape_cr) + +print "Number of canonical faces in the initial shape: %s" % init_nb_f +print "Number of canonical faces in the result shape: %s" % res_nb_f + # Publish in the study geompy.addToStudy( shape_igs, 'Import from IGS' ) geompy.addToStudy( shape_cr, 'Canonical Recognition' ) diff --git a/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg.png b/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg.png index 1c724a9..d772999 100644 Binary files a/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg.png and b/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg.png differ diff --git a/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg_stat.png b/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg_stat.png new file mode 100644 index 0000000..3a6a614 Binary files /dev/null and b/doc/salome/gui/CANRECPLUGIN/images/canrec_plugin_dlg_stat.png differ diff --git a/doc/salome/gui/CANRECPLUGIN/input/canrecplugin_usage_page.doc b/doc/salome/gui/CANRECPLUGIN/input/canrecplugin_usage_page.doc index c654a5a..bc2da0b 100644 --- a/doc/salome/gui/CANRECPLUGIN/input/canrecplugin_usage_page.doc +++ b/doc/salome/gui/CANRECPLUGIN/input/canrecplugin_usage_page.doc @@ -6,19 +6,30 @@ To create a Canonical Recognition in the Main Menu select New E This Operation constructs a canonical recognition (convert, if possible, a NURBS geometry B-Spline / Bezier curve or surface to its analytical form) of an \b Object. To constructs the canonical recognition you need to define the shape. +\n Once you chose an object you can see the number of canonical faces in this object on the label below. \n Merge Surfaces checkbox allows to merge surfaces in the result shape. \n Merge Curves checkbox allows to merge curvies in the result shape. \n The \b Result of the operation will be any \b GEOM_Object. -\n TUI Command: geompy.MakeCanonicalRecognition(Shape, MergeSurf, MergeCurves), +\n TUI Commands: +
    +
  • geompy.MakeCanonicalRecognition(Shape, MergeSurf, MergeCurves, theTolerance=0.01), where Shape is a shape to be converted into canonical recognition, -MergeSurf and MergeCurv flags to merge surfaces / curves in the result shape. - +MergeSurf and MergeCurv flags to merge surfaces / curves in the result shape, +theTolerance is the tolerance of the operation. Default value is 0.01.
  • +
  • geompy.GetNbCanonicalFaces(Shape), where Shape is a shape to be tested. +Returns the number of canonical faces in this shape.
  • +
\n Arguments: Name + one object. \image html canrec_plugin_dlg.png +Once the user presses the \b Apply or Apply and Close buttons, +he will be given with the operation statistics information: + +\image html canrec_plugin_dlg_stat.png + \n \b Example: Our TUI Script provide you with useful example of the use of \ref canrec_example "Canonical Recognition". diff --git a/idl/CANRECPlugin.idl b/idl/CANRECPlugin.idl index 9bdad0a..3d57c46 100644 --- a/idl/CANRECPlugin.idl +++ b/idl/CANRECPlugin.idl @@ -24,6 +24,8 @@ module CANRECPlugin { + typedef sequence ListOfLong; + /*! * \brief Interface to Canonical Recognition modeling functions. */ @@ -36,13 +38,33 @@ module CANRECPlugin * \param theMergeSurf the flag to switch on/off merging surfaces in the result shape. * \param theMergeCurves the flag to switch on/off merging curves in the result shape. * \param theTolerance the tolerance of the canonical recognition operation. + * \param theStat the statistics of the operation. Output parameter. + * Each integer value in the sequence has its own meaning + * depending on its index: + * 0 - total number of faces in the initial shape; + * 1 - number of canonical faces in the initial shape; + * 2 - number of faces converted to the canonical form; + * 3 - number of merged surfaces; + * 4 - number of merged curves. + * Nagative value means that this value is not computed. * * \return New GEOM_Object, containing the canonical recognition of the input object. */ - GEOM::GEOM_Object MakeCanonicalRecognition ( in GEOM::GEOM_Object theObject, - in boolean theMergeSurf, - in boolean theMergeCurves, - in double theTolerance ); + GEOM::GEOM_Object MakeCanonicalRecognition + (in GEOM::GEOM_Object theObject, + in boolean theMergeSurf, + in boolean theMergeCurves, + in double theTolerance, + out ListOfLong theStat); + + /*! + * \brief Get the number of canonical faces in the shape. + * + * \param theObject the input object (solid, compound, compsolid). + * + * \return the number of canonical faces in the object. + */ + long GetNbCanonicalFaces(in GEOM::GEOM_Object theObject); }; }; diff --git a/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.cc b/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.cc index e6b3b6e..677edb7 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.cc +++ b/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.cc @@ -49,27 +49,79 @@ GEOM::GEOM_Object_ptr CANRECPluginEngine_IOperations_i::MakeCanonicalRecognition( GEOM::GEOM_Object_ptr theObject, CORBA::Boolean theMergeSurf, CORBA::Boolean theMergeCurves, - CORBA::Double theTolerance ) + CORBA::Double theTolerance, + CANRECPlugin::ListOfLong_out theStat ) { + theStat = new CANRECPlugin::ListOfLong(); + // Set a not done flag GetOperations()->SetNotDone(); // Get the reference points Handle(GEOM_Object) anInitObject = GetObjectImpl( theObject ); - if ( anInitObject.IsNull() ) return GEOM::GEOM_Object::_nil(); + if ( anInitObject.IsNull() ) { + return GEOM::GEOM_Object::_nil(); + } // Make Canonical Recognition - Handle(GEOM_Object) anObject = GetOperations()->MakeCanonicalRecognition( anInitObject, - theMergeSurf, - theMergeCurves, - theTolerance ); - if ( !GetOperations()->IsDone() || anObject.IsNull() ) + Handle(TColStd_HSequenceOfInteger) aStat = new TColStd_HSequenceOfInteger; + Handle(GEOM_Object) anObject = + GetOperations()->MakeCanonicalRecognition(anInitObject, + theMergeSurf, + theMergeCurves, + theTolerance, + aStat); + + if (!GetOperations()->IsDone() || anObject.IsNull()) { return GEOM::GEOM_Object::_nil(); + } + + // Copy statistics. + int nbInts = aStat->Length(); + int i; + + theStat->length(nbInts); + + for (i = 0; i < nbInts; i++) { + theStat[i] = aStat->Value(i + 1); + } return GetObject( anObject ); } +//============================================================================= +/*! + * \brief Get the number of canonical faces in the shape. + * + * \param theObject the input object (solid, compound, compsolid). + * + * \return the number of canonical faces in the object. + */ +//============================================================================= +CORBA::Long CANRECPluginEngine_IOperations_i::GetNbCanonicalFaces + (GEOM::GEOM_Object_ptr theObject) +{ + // Set a not done flag + GetOperations()->SetNotDone(); + + // Get the reference points + Handle(GEOM_Object) anInitObject = GetObjectImpl(theObject); + + if (anInitObject.IsNull()) { + return -1; + } + + // Get the number of canonical faces. + CORBA::Long aResult = GetOperations()->GetNbCanonicalFaces(anInitObject); + + if (!GetOperations()->IsDone()) { + return -1; + } + + return aResult; +} + ::CANRECPluginImpl_IOperations* CANRECPluginEngine_IOperations_i::GetOperations() { return (::CANRECPluginImpl_IOperations*)GetImpl(); diff --git a/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.hh b/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.hh index 419c2c0..14502bb 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.hh +++ b/src/CANRECPLUGINEngine/CANRECPluginEngine_IOperations_i.hh @@ -43,7 +43,10 @@ class CANRECPLUGINENGINE_EXPORT CANRECPluginEngine_IOperations_i : GEOM::GEOM_Object_ptr MakeCanonicalRecognition ( GEOM::GEOM_Object_ptr theObject, CORBA::Boolean theMergeSurf, CORBA::Boolean theMergeCurves, - CORBA::Double theTolerance ); + CORBA::Double theTolerance, + CANRECPlugin::ListOfLong_out theStat ); + + CORBA::Long GetNbCanonicalFaces(GEOM::GEOM_Object_ptr theObject); CANRECPluginImpl_IOperations* GetOperations(); }; diff --git a/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.cxx b/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.cxx index 107776d..15f07e7 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.cxx +++ b/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.cxx @@ -22,10 +22,19 @@ #include +#include #include +#include +#include #include +#include +#include +#include +#include + #include #include +#include #include #include @@ -35,12 +44,56 @@ #include #endif // CANREC_HASLICENSE +/** + * This function returns the number of shapes of a certain type. + * + * \param theShape the shape. + * \param theType the required type. + * \return the number of shapes of a certain type. + */ +static Standard_Integer GetNbShapes(const TopoDS_Shape &theShape, + const TopAbs_ShapeEnum theType) +{ + TopTools_IndexedMapOfShape aMapShapes; + + TopExp::MapShapes(theShape, theType, aMapShapes); + + const Standard_Integer aResult = aMapShapes.Extent(); + + return aResult; +} + const Standard_GUID& CANRECPluginImpl_Driver::GetID() { static Standard_GUID aGUID("7e1492bb-b4cd-4a40-ad8f-102902b0047e"); return aGUID; } +Standard_Integer CANRECPluginImpl_Driver::GetNbCanonicalFaces + (const TopoDS_Shape &theShape) +{ + TopExp_Explorer anExp(theShape, TopAbs_FACE); + TopLoc_Location aLoc; + Standard_Integer aNbSurf = 0; + TopTools_MapOfShape aMapFence; + + for (; anExp.More(); anExp.Next()) { + const TopoDS_Shape &aShFace = anExp.Current(); + + if (aMapFence.Add(aShFace)) { + TopoDS_Face aFace = TopoDS::Face(aShFace); + Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace, aLoc); + + if(aSurface->IsKind(STANDARD_TYPE(Geom_Plane)) || + ShapeConvert_Surface::IsCanonical(aSurface)) { + aNbSurf++; + } + } + } + + return aNbSurf; +} + CANRECPluginImpl_Driver::CANRECPluginImpl_Driver() { } @@ -86,6 +139,9 @@ Standard_Integer CANRECPluginImpl_Driver::Execute( TFunction_Logbook& log ) cons aRecognizer.SurfaceMode() = isNeedMergeSurf; aRecognizer.CurveMode() = isNeedMergeCurves; + const Standard_Integer anInitNbFaces = GetNbShapes(aShape, TopAbs_FACE); + const Standard_Integer anInitNbCanonical = GetNbCanonicalFaces(aShape); + // 1. Recognizing aRecognizer.SetShape( aShape ); aRecognizer.UnifyMode() = false; @@ -97,22 +153,41 @@ Standard_Integer CANRECPluginImpl_Driver::Execute( TFunction_Logbook& log ) cons aSewing.Add( aResultingShape ); aSewing.Perform(); aResultingShape = aSewing.SewedShape(); - + + const Standard_Integer aNbConverted = + GetNbCanonicalFaces(aResultingShape) - anInitNbCanonical; + Standard_Integer aNbMergedFaces = -1; + Standard_Integer aNbMergedEdges = -1; + // 3.1. Union Surfaces if ( isNeedMergeSurf ) { ShapeConvert_UnionFaces aFaceUnifier; aFaceUnifier.GetTolerance() = aTolerance; aResultingShape = aFaceUnifier.Perform( aResultingShape ); + aNbMergedFaces = anInitNbFaces - GetNbShapes(aResultingShape, TopAbs_FACE); } // 3.2. Union Curves if ( isNeedMergeCurves ) { ShapeConvert_UnionEdges anEdgeUnifier; - aResultingShape = anEdgeUnifier.Perform( aResultingShape, aTolerance ); + aNbMergedEdges = GetNbShapes(aResultingShape, TopAbs_EDGE); + aResultingShape = anEdgeUnifier.Perform( aResultingShape, aTolerance ); + aNbMergedEdges -= GetNbShapes(aResultingShape, TopAbs_EDGE); } if ( aResultingShape.IsNull() ) return 0; + // Create statistics + Handle(TColStd_HArray1OfInteger) aStat = new TColStd_HArray1OfInteger(1, 5); + + aStat->SetValue(1, anInitNbFaces); + aStat->SetValue(2, anInitNbCanonical); + aStat->SetValue(3, aNbConverted); + aStat->SetValue(4, aNbMergedFaces); + aStat->SetValue(5, aNbMergedEdges); + + aData.SetStatistics(aStat); + aFunction->SetValue( aResultingShape ); log.SetTouched( Label() ); diff --git a/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.hxx b/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.hxx index 68266ba..1b18418 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.hxx +++ b/src/CANRECPLUGINEngine/CANRECPluginImpl_Driver.hxx @@ -22,6 +22,8 @@ #include +class TopoDS_Shape; + DEFINE_STANDARD_HANDLE( CANRECPluginImpl_Driver, GEOM_BaseDriver ); class CANRECPluginImpl_Driver : public GEOM_BaseDriver @@ -31,6 +33,7 @@ public: ~CANRECPluginImpl_Driver(); static const Standard_GUID& GetID(); + static Standard_Integer GetNbCanonicalFaces(const TopoDS_Shape &theShape); virtual Standard_Integer Execute( TFunction_Logbook& ) const; Standard_Boolean MustExecute( const TFunction_Logbook& ) const; virtual void Validate( TFunction_Logbook& ) const; diff --git a/src/CANRECPLUGINEngine/CANRECPluginImpl_ICanRec.hxx b/src/CANRECPLUGINEngine/CANRECPluginImpl_ICanRec.hxx index 111aa48..41a578e 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginImpl_ICanRec.hxx +++ b/src/CANRECPLUGINEngine/CANRECPluginImpl_ICanRec.hxx @@ -21,11 +21,13 @@ #define __CANRECPLUGINIMPL_ICANREC_HXX #include +#include #define CanonicalRecognition_ARG_NeedMergeSurf 1 #define CanonicalRecognition_ARG_NeedMergeCurves 2 #define CanonicalRecognition_ARG_Tolerance 3 #define CanonicalRecognition_ARG_Object 4 +#define CanonicalRecognition_ARG_Stat 5 class CANRECPluginImpl_ICanRec { @@ -44,6 +46,9 @@ public: void SetObject(Handle(GEOM_Function) anInitialObject) { _func->SetReference(CanonicalRecognition_ARG_Object, anInitialObject); } Handle(GEOM_Function) GetObject() { return _func->GetReference(CanonicalRecognition_ARG_Object); } + void SetStatistics(const Handle(TColStd_HArray1OfInteger) &theStat) { _func->SetIntegerArray(CanonicalRecognition_ARG_Stat, theStat); } + Handle(TColStd_HArray1OfInteger) GetStatistics() { return _func->GetIntegerArray(CanonicalRecognition_ARG_Stat); } + private: Handle(GEOM_Function) _func; }; diff --git a/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.cxx b/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.cxx index 9fdb532..81b20d8 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.cxx +++ b/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.cxx @@ -46,17 +46,27 @@ CANRECPluginImpl_IOperations::~CANRECPluginImpl_IOperations() * \param theMergeCurves set merging curves * \param theTolerance set tolerance * \param theObject is initial object + * \param theStat is the statistics. A set of integers. For details please + * see CANRECPlugin.idl * \return New GEOM_Object, containing the created shape. */ //============================================================================= Handle(GEOM_Object) -CANRECPluginImpl_IOperations::MakeCanonicalRecognition ( Handle(GEOM_Object) theObject, - bool theMergeSurf, - bool theMergeCurves, - double theTolerance ) +CANRECPluginImpl_IOperations::MakeCanonicalRecognition + (Handle(GEOM_Object) theObject, + bool theMergeSurf, + bool theMergeCurves, + double theTolerance, + Handle_TColStd_HSequenceOfInteger &theStat) { SetErrorCode( KO ); + if (theStat.IsNull()) { + theStat = new TColStd_HSequenceOfInteger; + } else { + theStat->Clear(); + } + if ( theObject.IsNull() ) return NULL; // Add a new object @@ -92,6 +102,17 @@ CANRECPluginImpl_IOperations::MakeCanonicalRecognition ( Handle(GEOM_Object) the SetErrorCode( aFail->GetMessageString() ); return NULL; } + + Handle(TColStd_HArray1OfInteger) anArray = aData.GetStatistics(); + + if (anArray.IsNull() == Standard_False) { + Standard_Integer i = anArray->Lower(); + const Standard_Integer iUp = anArray->Upper(); + + for (; i <= iUp; ++i) { + theStat->Append(anArray->Value(i)); + } + } // Make a Python command GEOM::TPythonDump(aFunction) << aShape << " = " << "geompy.MakeCanonicalRecognition(" << @@ -101,3 +122,35 @@ CANRECPluginImpl_IOperations::MakeCanonicalRecognition ( Handle(GEOM_Object) the return aShape; } + +//============================================================================= +/*! + * \brief Get the number of canonical faces in the shape. + * + * \param theObject the input object (solid, compound, compsolid). + * + * \return the number of canonical faces in the object. + */ +//============================================================================= +Standard_Integer CANRECPluginImpl_IOperations::GetNbCanonicalFaces + (const Handle(GEOM_Object) &theObject) +{ + SetErrorCode(KO); + + TopoDS_Shape aShape = theObject->GetValue(); + + if (aShape.IsNull()) { + return -1; + } + + const Standard_Integer aResult = + CANRECPluginImpl_Driver::GetNbCanonicalFaces(aShape); + + if (aResult >= 0) { + SetErrorCode(OK); + + return aResult; + } + + return -1; +} diff --git a/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.hxx b/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.hxx index 2d7ba11..3be84a9 100644 --- a/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.hxx +++ b/src/CANRECPLUGINEngine/CANRECPluginImpl_IOperations.hxx @@ -23,6 +23,8 @@ #include #include +#include + class GEOM_Engine; class CANRECPluginImpl_IOperations: public GEOM_IOperations @@ -31,10 +33,15 @@ public: Standard_EXPORT CANRECPluginImpl_IOperations( GEOM_Engine* theEngine, int theDocID ); Standard_EXPORT ~CANRECPluginImpl_IOperations(); - Standard_EXPORT Handle(GEOM_Object) MakeCanonicalRecognition ( Handle(GEOM_Object) theObject, - bool theMergeSurf, - bool theMergeCurves, - double theTolerance ); + Standard_EXPORT Handle(GEOM_Object) MakeCanonicalRecognition + (Handle(GEOM_Object) theObject, + bool theMergeSurf, + bool theMergeCurves, + double theTolerance, + Handle_TColStd_HSequenceOfInteger &theStat); + + Standard_EXPORT Standard_Integer GetNbCanonicalFaces + (const Handle(GEOM_Object) &theObject); }; #endif // __CANRECPLUGINIMPL_IOPERATIONS_HXX diff --git a/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.cxx b/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.cxx index 8de9222..8c899a5 100644 --- a/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.cxx +++ b/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.cxx @@ -59,7 +59,8 @@ // Constructor //================================================================================= CANRECPluginGUI_CanonicalRecognitionDlg::CANRECPluginGUI_CanonicalRecognitionDlg( GeometryGUI* theGeometryGUI, QWidget* parent ) -: GEOMBase_Skeleton(theGeometryGUI, parent, false) +: GEOMBase_Skeleton(theGeometryGUI, parent, false), + myNbFacesLbl(0) { QString aPluginName = "CANRECPlugin"; QPixmap imageOp (SUIT_Session::session()->resourceMgr()->loadPixmap( aPluginName, tr( "ICO_CANONICALRECOGNITION" ) ) ); @@ -94,6 +95,9 @@ CANRECPluginGUI_CanonicalRecognitionDlg::CANRECPluginGUI_CanonicalRecognitionDlg PButton1->setIcon( image1 ); PButton1->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + // Label with number of faces. + myNbFacesLbl = new QLabel(argGroup); + // 2. Object QLabel* textLabel1 = new QLabel( argGroup ); textLabel1->setText( tr( "CANRECPLUGIN_ARG_OBJ" ) ); @@ -118,12 +122,13 @@ CANRECPluginGUI_CanonicalRecognitionDlg::CANRECPluginGUI_CanonicalRecognitionDlg lay->addWidget( textLabel1, 0, 0 ); lay->addWidget( PButton1, 0, 1 ); lay->addWidget( LineEdit1, 0, 2 ); + lay->addWidget(myNbFacesLbl, 1, 0, 1, 3); - lay->addWidget( textLabel2, 1, 0, 1, 2 ); - lay->addWidget( SpinBoxTol, 1, 2 ); + lay->addWidget( textLabel2, 2, 0, 1, 2 ); + lay->addWidget( SpinBoxTol, 2, 2 ); - lay->addWidget( CheckButton1, 2, 0, 1, 3 ); - lay->addWidget( CheckButton2, 3, 0, 1, 3 ); + lay->addWidget( CheckButton1, 3, 0, 1, 3 ); + lay->addWidget( CheckButton2, 4, 0, 1, 3 ); myHelpFileName = "canrecplugin_usage_page.html"; myHelpContext = aPluginName.toUpper(); @@ -253,7 +258,9 @@ bool CANRECPluginGUI_CanonicalRecognitionDlg::execute( ObjectList& objects ) CORBA::Double aTolerance = SpinBoxTol->value(); // call engine function - anObj = anOper->MakeCanonicalRecognition( myObject.get(), aMergeSurf, aMergeCurves, aTolerance ); + CANRECPlugin::ListOfLong_var aStat; + + anObj = anOper->MakeCanonicalRecognition( myObject.get(), aMergeSurf, aMergeCurves, aTolerance, aStat ); res = !anObj->_is_nil(); if ( res && !IsPreview() ) { @@ -265,6 +272,31 @@ bool CANRECPluginGUI_CanonicalRecognitionDlg::execute( ObjectList& objects ) if ( aParameters.count() > 0 ) anObj->SetParameters( aParameters.join(":").toLatin1().constData() ); + + + // Display message box with statistics. + // Compose statistics string. + QString aStatString = tr("CANRECPLUGIN_INFO_TEXT_CAPTION"); + + aStatString += "\n\n\t"; + aStatString += tr("CANRECPLUGIN_INFO_TEXT_NB_FACES_INIT").arg(aStat[0]); + aStatString += "\n\t"; + aStatString += tr("CANRECPLUGIN_INFO_TEXT_NB_CAN_FACES_INIT").arg(aStat[1]); + aStatString += "\n\t"; + aStatString += tr("CANRECPLUGIN_INFO_TEXT_NB_FACES").arg(aStat[2]); + + if (CheckButton1->isChecked()) { + aStatString += "\n\t"; + aStatString += tr("CANRECPLUGIN_INFO_TEXT_MERGED_SURF").arg(aStat[3]); + } + + if (CheckButton2->isChecked()) { + aStatString += "\n\t"; + aStatString += tr("CANRECPLUGIN_INFO_TEXT_MERGED_CURV").arg(aStat[4]); + } + + SUIT_MessageBox::information + (this, tr("CANRECPLUGIN_INFO_TITLE"), aStatString); } if ( res ) @@ -286,9 +318,32 @@ void CANRECPluginGUI_CanonicalRecognitionDlg::SelectionIntoArgument() { myObject = selected.first(); LineEdit1->setText( myObject->GetName() ); + + // Get statistics of initial shape. + CANRECPlugin::ICanRecOperations_var anOper = + CANRECPlugin::ICanRecOperations::_narrow( getOperation() ); + const int aNbCanFaces = + anOper->GetNbCanonicalFaces(myObject.get()); + TopoDS_Shape aShape; + + if (GEOMBase::GetShape(myObject.get(), aShape) && !aShape.IsNull()) { + // Get the tolal number of faces. + TopTools_IndexedMapOfShape aMapShapes; + + TopExp::MapShapes(aShape, TopAbs_FACE, aMapShapes); + + const Standard_Integer aNbFaces = aMapShapes.Extent(); + + myNbFacesLbl->setText(tr("CANRECPLUGIN_ARG_NB_CAN_FACES"). + arg(aNbCanFaces).arg(aNbFaces)); + } else { + myNbFacesLbl->setText(tr("CANRECPLUGIN_ARG_NB_CAN_FACES_NO_OBJECT")); + } } - else + else { LineEdit1->setText( "" ); + myNbFacesLbl->setText(tr("CANRECPLUGIN_ARG_NB_CAN_FACES_NO_OBJECT")); + } } //================================================================================= diff --git a/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.h b/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.h index 15ae7a5..1899653 100644 --- a/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.h +++ b/src/CANRECPLUGINGUI/CANRECPluginGUI_CanonicalRecognitionDlg.h @@ -63,6 +63,7 @@ private: SalomeApp_DoubleSpinBox* SpinBoxTol; QCheckBox* CheckButton1; QCheckBox* CheckButton2; + QLabel *myNbFacesLbl; GEOM::GeomObjPtr myObject; }; diff --git a/src/CANRECPLUGINGUI/resources/CANRECPlugin_msg_en.ts b/src/CANRECPLUGINGUI/resources/CANRECPlugin_msg_en.ts index fba0e94..e69d60d 100644 --- a/src/CANRECPLUGINGUI/resources/CANRECPlugin_msg_en.ts +++ b/src/CANRECPLUGINGUI/resources/CANRECPlugin_msg_en.ts @@ -62,5 +62,41 @@ CANRECPLUGIN_ARG_TOLERANCE Tolerance + + CANRECPLUGIN_ARG_NB_CAN_FACES_NO_OBJECT + Number of canonical faces: + + + CANRECPLUGIN_ARG_NB_CAN_FACES + Number of canonical faces: %1 of %2 + + + CANRECPLUGIN_INFO_TITLE + Operation Statistics + + + CANRECPLUGIN_INFO_TEXT_CAPTION + Operation Statistics: + + + CANRECPLUGIN_INFO_TEXT_NB_FACES_INIT + Total number of faces in the initial shape: %1 + + + CANRECPLUGIN_INFO_TEXT_NB_CAN_FACES_INIT + Number of canonical faces in the initial shape: %1 + + + CANRECPLUGIN_INFO_TEXT_NB_FACES + Number of faces converted to the canonical form: %1 + + + CANRECPLUGIN_INFO_TEXT_MERGED_SURF + Number of merged surfaces: %1 + + + CANRECPLUGIN_INFO_TEXT_MERGED_CURV + Number of merged curves: %1 + diff --git a/src/CANRECPLUGIN_PY/CANRECPluginBuilder.py b/src/CANRECPLUGIN_PY/CANRECPluginBuilder.py index e4c9c01..8dfda9a 100644 --- a/src/CANRECPLUGIN_PY/CANRECPluginBuilder.py +++ b/src/CANRECPLUGIN_PY/CANRECPluginBuilder.py @@ -69,8 +69,37 @@ def MakeCanonicalRecognition(self, theObj, theMergeSurf, theMergeCurves, from salome.geom.geomBuilder import ParseParameters, RaiseIfFailed anOp = GetCANRECOperations(self) theMergeSurf, theMergeCurves, theTolerance, Parameters = ParseParameters(theMergeSurf, theMergeCurves, theTolerance) - anObj = anOp.MakeCanonicalRecognition(theObj, theMergeSurf, theMergeCurves, theTolerance) + (anObj, aStat) = anOp.MakeCanonicalRecognition(theObj, theMergeSurf, theMergeCurves, theTolerance) RaiseIfFailed("MakeCanonicalRecognition", anOp) self._autoPublish(anObj, theName, "canonical") anOp.UnRegister() + print "Total number of faces in the initial shape: %s" % aStat[0] + print "Number of canonical faces in the initial shape: %s" % aStat[1] + print "Number of faces converted to the canonical form: %s" % aStat[2] + if aStat[3] >= 0: + print "Number of merged surfaces: %s" % aStat[3] + if aStat[4] >= 0: + print "Number of merged curves: %s" % aStat[4] + return anObj + +## Get the number of canonical faces in the shape. +# @param theObj the input object (solid, compound, compsolid). +# +# @return the number of canonical faces in the object. +def GetNbCanonicalFaces(self, theObj): + """ + Get the number of canonical faces in the shape. + + Parameters: + theObj the input object (solid, compound, compsolid). + + Returns: + the number of canonical faces in the object. + """ + from salome.geom.geomBuilder import RaiseIfFailed + anOp = GetCANRECOperations(self) + aNbCanFaces = anOp.GetNbCanonicalFaces(theObj) + RaiseIfFailed("GetNbCanonicalFaces", anOp) + anOp.UnRegister() + return aNbCanFaces