From: skv Date: Mon, 13 Oct 2014 08:14:17 +0000 (+0400) Subject: 0022750: [EDF] Improve ergonomics of the "Detect Self-intersections" dialog box X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=291495de5e1eca20b3f960cf5ac008c32f41888a;p=modules%2Fgeom.git 0022750: [EDF] Improve ergonomics of the "Detect Self-intersections" dialog box --- diff --git a/doc/salome/gui/GEOM/images/measures11.png b/doc/salome/gui/GEOM/images/measures11.png index 85af6f187..fc1cea582 100644 Binary files a/doc/salome/gui/GEOM/images/measures11.png and b/doc/salome/gui/GEOM/images/measures11.png differ diff --git a/doc/salome/gui/GEOM/input/check_self_intersections.doc b/doc/salome/gui/GEOM/input/check_self_intersections.doc index 86c556786..7446f3dd3 100644 --- a/doc/salome/gui/GEOM/input/check_self_intersections.doc +++ b/doc/salome/gui/GEOM/input/check_self_intersections.doc @@ -8,9 +8,16 @@ This operation checks the topology of the selected shape to detect self-intersec In this dialog: -- \b Object - the checked object. \b Selection button allows picking it in the viewer or in the object browser. -- \b Errors list contains the list of intersections. Select the intersection to show Incriminated Sub-shapes in the field to the right. - +- \b Object - the checked object. \b Selection button allows picking it in the viewer or in the object browser. +- Level of check - The combo box that allows to set the level of checking shape on self-interference. + It defines which interferferences will be checked. Default value is "All interferences". +- Compute self-intersections button computes self-interferences. +- \b Summary section contains the general report if the object has self-intersections and/or if errors are occured during computation. +- \b Self-intersections list contains the list of self-intersections detected. +Select the intersection to show Sub-shapes in the field to the right. +- \b Apply and Apply and Close buttons are used to store selected self-intersected shapes in the study for further analysis. +If no shapes are selected, but an intersection is selected the both of intersected shapes are stored. If no intersections selected +all shapes of all intersections are stored in the study. \note This tool is useful for detection of shapes, not suitable for arguments of Boolean operations and Partition algorithm. @@ -18,8 +25,10 @@ For more information about Partition and Boolean Operations Algorithms and their limitations refer to this document. \n Result: Boolean. -\n TUI Command: geompy.CheckSelfIntersections(theShape), -where \em theShape is the shape checked for validity. +\n TUI Command: geompy.CheckSelfIntersections(theShape, theCheckLevel = GEOM.SI_ALL), \n +where: \n +\em theShape is the shape checked for validity. \n +\em theCheckLevel is the level of check. Default value is GEOM.SI_ALL to check all interferences. See also a \ref tui_check_self_intersections_page "TUI example". diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 7253abf9f..7679626b7 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -187,6 +187,20 @@ module GEOM FDT_String }; + /** + * This enumeration represents the level of checking shape on + * self-interference. It defines which interferferences will be checked. + */ + enum si_check_level + { + SI_V_V, // only V/V interferences + SI_V_E, // V/V and V/E interferences + SI_E_E, // V/V, V/E and E/E interferences + SI_V_F, // V/V, V/E, E/E and V/F interferences + SI_E_F, // V/V, V/E, E/E, V/F and E/F interferences + SI_ALL // all interferences + }; + /*! * \brief Object creation parameters @@ -4080,10 +4094,12 @@ module GEOM /*! * \brief Check a topology of the given shape on self-intersections presence. * \param theShape Shape to check validity of. + * \param theCheckLevel the level of self-interference check. * \param theIntersections Output. List of intersected sub-shapes IDs, it contains pairs of IDs. * \return TRUE, if the shape does not have any self-intersections. */ boolean CheckSelfIntersections (in GEOM_Object theShape, + in long theCheckLevel, out ListOfLong theIntersections); /*! diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index a732e5004..5b5c8bb63 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -415,22 +415,6 @@ Please, select face, shell or solid and try again GEOM_CHECK_SELF_INTERSECTIONS Detect Self-intersections - - GEOM_CHECK_SELF_INTERSECTIONS_FAILED - Detection of self-intersections failed - - - GEOM_NO_SELF_INTERSECTIONS - There are no self-intersections in the shape - - - GEOM_SELF_INTERSECTIONS_FOUND - Some self-intersections detected - - - GEOM_CHECK_SELF_INTERSECTIONS_ERRORS - Warning: there were errors during the operation, so the list may be incomplete. - GEOM_CIRCLE Circle @@ -6967,4 +6951,71 @@ Do you want to create new material? V-Isoline + + MeasureGUI_CheckSelfIntersectionsDlg + + GEOM_CHECK_INTE_INTERSECTIONS + Self-intersections + + + GEOM_CHECK_INTE_SUBSHAPES + Sub-shapes + + + GEOM_CHECK_INTE_CHECK_LEVEL + Level of check + + + GEOM_CHECK_INTE_SUMMARY + Summary + + + GEOM_CHECK_INTE_COMPUTE + Compute self-intersections + + + GEOM_SELF_INTERSECTION_NAME + Self_intersection + + + GEOM_NO_SELF_INTERSECTIONS + There are no self-intersections in the shape + + + GEOM_SELF_INTERSECTIONS_FOUND + Some self-intersections detected + + + GEOM_CHECK_SELF_INTERSECTIONS_FAILED + Detection of self-intersections failed + + + GEOM_CHECK_SELF_INTERSECTIONS_ERRORS + Warning: there were errors during the operation, so the list may be incomplete. + + + GEOM_CHECK_INTE_V_V + Vertex to Vertex + + + GEOM_CHECK_INTE_V_E + Vertex to Edge + all above + + + GEOM_CHECK_INTE_E_E + Edge to Edge + all above + + + GEOM_CHECK_INTE_V_F + Vertex to Face + all above + + + GEOM_CHECK_INTE_E_F + Edge to Face + all above + + + GEOM_CHECK_INTE_ALL + All interferences + + diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 0764495dc..fb2320ea5 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -1501,6 +1501,7 @@ TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors //============================================================================= bool GEOMImpl_IMeasureOperations::CheckSelfIntersections (Handle(GEOM_Object) theShape, + const SICheckLevel theCheckLevel, Handle(TColStd_HSequenceOfInteger)& theIntersections) { SetErrorCode(KO); @@ -1534,6 +1535,7 @@ bool GEOMImpl_IMeasureOperations::CheckSelfIntersections // BOPAlgo_CheckerSI aCSI; // checker of self-interferences aCSI.SetArguments(aLCS); + aCSI.SetLevelOfCheck(theCheckLevel); // 1. Launch the checker aCSI.Perform(); diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index 86d0a9c7b..3b8ae3d42 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -85,6 +85,20 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { SK_ADVANCED, // all advanced shapes (temporary implementation) }; + /** + * This enumeration represents the level of checking shape on + * self-interference. It defines which interferferences will be checked. + */ + enum SICheckLevel + { + SI_V_V = 0, // only V/V interferences + SI_V_E, // V/V and V/E interferences + SI_E_E, // V/V, V/E and E/E interferences + SI_V_F, // V/V, V/E, E/E and V/F interferences + SI_E_F, // V/V, V/E, E/E, V/F and E/F interferences + SI_ALL // all interferences + }; + Standard_EXPORT ShapeKind KindOfShape (Handle(GEOM_Object) theShape, Handle(TColStd_HSequenceOfInteger)& theIntegers, Handle(TColStd_HSequenceOfReal)& theDoubles); @@ -141,6 +155,7 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { const std::list &theErrors); Standard_EXPORT bool CheckSelfIntersections (Handle(GEOM_Object) theShape, + const SICheckLevel theCheckLevel, Handle(TColStd_HSequenceOfInteger)& theIntersections); Standard_EXPORT TCollection_AsciiString IsGoodForSolid (Handle(GEOM_Object) theShape); diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index b6785bda9..0d4a89eff 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -706,6 +706,7 @@ char* GEOM_IMeasureOperations_i::PrintShapeErrors */ //============================================================================= CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape, + CORBA::Long theCheckLevel, GEOM::ListOfLong_out theIntersections) { // Set a not done flag @@ -720,10 +721,35 @@ CORBA::Boolean GEOM_IMeasureOperations_i::CheckSelfIntersections (GEOM::GEOM_Obj Handle(GEOM_Object) aShape = GetObjectImpl(theShape); if (!aShape.IsNull()) { + GEOMImpl_IMeasureOperations::SICheckLevel aCheckLevel; + + switch(theCheckLevel) { + case GEOM::SI_V_V: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_V; + break; + case GEOM::SI_V_E: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_E; + break; + case GEOM::SI_E_E: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_E; + break; + case GEOM::SI_V_F: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_V_F; + break; + case GEOM::SI_E_F: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_E_F; + break; + case GEOM::SI_ALL: + default: + aCheckLevel = GEOMImpl_IMeasureOperations::SI_ALL; + break; + } + Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger; // Detect self-intersections - isGood = GetOperations()->CheckSelfIntersections(aShape, anIntegers); + isGood = GetOperations()->CheckSelfIntersections + (aShape, aCheckLevel, anIntegers); int nbInts = anIntegers->Length(); diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index 690ac5390..391de3f48 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -97,6 +97,7 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i : const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors); CORBA::Boolean CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape, + CORBA::Long theCheckLevel, GEOM::ListOfLong_out theIntersections); char* IsGoodForSolid (GEOM::GEOM_Object_ptr theShape); diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index a72a7d283..976f9e9fb 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -10569,22 +10569,38 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): ## Detect self-intersections in the given shape. # @param theShape Shape to check. + # @param theCheckLevel is the level of self-intersection check. + # Possible input values are: + # - GEOM.SI_V_V(0) - only V/V interferences + # - GEOM.SI_V_E(1) - V/V and V/E interferences + # - GEOM.SI_E_E(2) - V/V, V/E and E/E interferences + # - GEOM.SI_V_F(3) - V/V, V/E, E/E and V/F interferences + # - GEOM.SI_E_F(4) - V/V, V/E, E/E, V/F and E/F interferences + # - GEOM.SI_ALL(5) - all interferences. # @return TRUE, if the shape contains no self-intersections. # # @ref tui_measurement_tools_page "Example" @ManageTransactions("MeasuOp") - def CheckSelfIntersections(self, theShape): + def CheckSelfIntersections(self, theShape, theCheckLevel = GEOM.SI_ALL): """ Detect self-intersections in the given shape. Parameters: theShape Shape to check. - + theCheckLevel is the level of self-intersection check. + Possible input values are: + - GEOM.SI_V_V(0) - only V/V interferences + - GEOM.SI_V_E(1) - V/V and V/E interferences + - GEOM.SI_E_E(2) - V/V, V/E and E/E interferences + - GEOM.SI_V_F(3) - V/V, V/E, E/E and V/F interferences + - GEOM.SI_E_F(4) - V/V, V/E, E/E, V/F and E/F interferences + - GEOM.SI_ALL(5) - all interferences. + Returns: TRUE, if the shape contains no self-intersections. """ # Example: see GEOM_TestMeasures.py - (IsValid, Pairs) = self.MeasuOp.CheckSelfIntersections(theShape) + (IsValid, Pairs) = self.MeasuOp.CheckSelfIntersections(theShape, EnumToLong(theCheckLevel)) RaiseIfFailed("CheckSelfIntersections", self.MeasuOp) return IsValid diff --git a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx index 8debf294c..de58de84c 100644 --- a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx @@ -24,8 +24,9 @@ // File : MeasureGUI_CheckSelfIntersectionsDlg.cxx #include "MeasureGUI_CheckSelfIntersectionsDlg.h" -#include "MeasureGUI_Widgets.h" +#include "MeasureGUI.h" +#include #include #include #include @@ -34,6 +35,7 @@ #include #include +#include #include #include @@ -41,6 +43,8 @@ #include #include +#include + #define TEXTEDIT_FONT_FAMILY "Courier" #define TEXTEDIT_FONT_SIZE 11 @@ -52,7 +56,14 @@ // true to construct a modal dialog. //================================================================================= MeasureGUI_CheckSelfIntersectionsDlg::MeasureGUI_CheckSelfIntersectionsDlg (GeometryGUI* GUI, QWidget* parent) - : MeasureGUI_Skeleton(GUI, parent, false) + : GEOMBase_Skeleton (GUI, parent, false), + myTextView (0), + mySelButton (0), + myEditObjName (0), + myLevelBox (0), + myComputeButton (0), + myInteList (0), + myShapeList (0) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_SELF_INTERSECTIONS"))); @@ -63,31 +74,64 @@ MeasureGUI_CheckSelfIntersectionsDlg::MeasureGUI_CheckSelfIntersectionsDlg (Geom /***************************************************************/ mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS")); mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton3->close(); + + QGroupBox *aGrp = new QGroupBox(tr("GEOM_CHECK_INFOS")); + QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT")); + QLabel *anInteLbl = new QLabel(tr("GEOM_CHECK_INTE_INTERSECTIONS")); + QLabel *aShapeLbl = new QLabel(tr("GEOM_CHECK_INTE_SUBSHAPES")); + QLabel *aLevelLbl = new QLabel(tr("GEOM_CHECK_INTE_CHECK_LEVEL")); + QLabel *aSummaryLbl = new QLabel(tr("GEOM_CHECK_INTE_SUMMARY")); + QFont aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE); - myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget()); - myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS")); - myGrp->TextLabel1->setText(tr("GEOM_OBJECT")); - - myGrp->TextView1->setReadOnly(true); - QFont aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE); aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias); - myGrp->TextView1->setFont(aFont); + myTextView = new QTextBrowser; + myTextView->setReadOnly(true); + myTextView->setFont(aFont); + + mySelButton = new QPushButton; + mySelButton->setIcon(image1); + mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + myEditObjName = new QLineEdit; + myEditObjName->setReadOnly(true); + + myLevelBox = new QComboBox; - myGrp->PushButton1->setIcon(image1); - myGrp->LineEdit1->setReadOnly(true); + myComputeButton = new QPushButton(tr("GEOM_CHECK_INTE_COMPUTE")); - myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS")); - myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES")); - myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection); + myInteList = new QListWidget; + myShapeList = new QListWidget; + myShapeList->setSelectionMode(QAbstractItemView::ExtendedSelection); + + QGridLayout *aGrpLayout = new QGridLayout(aGrp); + + aGrpLayout->setMargin(9); + aGrpLayout->setSpacing(6); + aGrpLayout->addWidget(anObjLbl, 0, 0); + aGrpLayout->addWidget(anInteLbl, 5, 0); + aGrpLayout->addWidget(aShapeLbl, 5, 2); + aGrpLayout->addWidget(aLevelLbl, 1, 0); + aGrpLayout->addWidget(myLevelBox, 1, 1, 1, 2); + aGrpLayout->addWidget(myComputeButton, 2, 0, 1, 3); + aGrpLayout->addWidget(aSummaryLbl, 3, 0); + aGrpLayout->addWidget(myTextView, 4, 0, 1, 3); + aGrpLayout->addWidget(mySelButton, 0, 1); + aGrpLayout->addWidget(myEditObjName, 0, 2); + aGrpLayout->addWidget(myInteList, 6, 0, 1, 2); + aGrpLayout->addWidget(myShapeList, 6, 2); QVBoxLayout* layout = new QVBoxLayout (centralWidget()); layout->setMargin(0); layout->setSpacing(6); - layout->addWidget(myGrp); + layout->addWidget(aGrp); /***************************************************************/ - myHelpFileName = "using_measurement_tools_page.html#check_self_intersections_anchor"; + myHelpFileName = "check_self_intersections_page.html"; /* Initialisation */ Init(); @@ -107,94 +151,302 @@ MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg() //================================================================================= void MeasureGUI_CheckSelfIntersectionsDlg::Init() { - mySelBtn = myGrp->PushButton1; - mySelEdit = myGrp->LineEdit1; - MeasureGUI_Skeleton::Init(); - - connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged())); - connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged())); + // Fill in the combo box. + myLevelBox->insertItem(GEOM::SI_V_V, tr("GEOM_CHECK_INTE_V_V")); + myLevelBox->insertItem(GEOM::SI_V_E, tr("GEOM_CHECK_INTE_V_E")); + myLevelBox->insertItem(GEOM::SI_E_E, tr("GEOM_CHECK_INTE_E_E")); + myLevelBox->insertItem(GEOM::SI_V_F, tr("GEOM_CHECK_INTE_V_F")); + myLevelBox->insertItem(GEOM::SI_E_F, tr("GEOM_CHECK_INTE_E_F")); + myLevelBox->insertItem(GEOM::SI_ALL, tr("GEOM_CHECK_INTE_ALL")); + myLevelBox->setCurrentIndex(GEOM::SI_ALL); + + connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), + this, SLOT(DeactivateActiveDialog())); + connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), + this, SLOT(ClickOnCancel())); + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + connect(mySelButton, SIGNAL(clicked()), + this, SLOT(SetEditCurrentArgument())); + connect(myInteList, SIGNAL(itemSelectionChanged()), + SLOT(onInteListSelectionChanged())); + connect(myShapeList, SIGNAL(itemSelectionChanged()), + SLOT(onSubShapesListSelectionChanged())); + connect(myLevelBox, SIGNAL(currentIndexChanged(int)), + this, SLOT(clear())); + connect(myComputeButton, SIGNAL(clicked()), this, SLOT(onCompute())); + + LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr(); + + connect(aSel, SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + initName( tr( "GEOM_SELF_INTERSECTION_NAME") ); + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); + myComputeButton->setEnabled(false); + activateSelection(); + SelectionIntoArgument(); } //================================================================================= -// function : processObject +// function : clear // purpose : //================================================================================= -void MeasureGUI_CheckSelfIntersectionsDlg::processObject() +void MeasureGUI_CheckSelfIntersectionsDlg::clear() { - myGrp->ListBox1->clear(); - myGrp->ListBox2->clear(); + myTextView->setText(""); + disconnect(myInteList, SIGNAL(itemSelectionChanged()), this, 0); + disconnect(myShapeList, SIGNAL(itemSelectionChanged()), this, 0); + myInteList->clear(); + myShapeList->clear(); + connect(myInteList, SIGNAL(itemSelectionChanged()), + SLOT(onInteListSelectionChanged())); + connect(myShapeList, SIGNAL(itemSelectionChanged()), + SLOT(onSubShapesListSelectionChanged())); erasePreview(); + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); + myComputeButton->setEnabled(true); +} - if (myObj->_is_nil()) - return; - - QString aMsg (""); - GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation()); - bool isGood = false, isFailed = false; - int nbPairs = 0; - try { - isGood = anOper->CheckSelfIntersections(myObj, myInters); - nbPairs = myInters->length()/2; - if (nbPairs*2 != myInters->length()) { - isFailed = true; - } - } - catch (const SALOME::SALOME_Exception& e) { - SalomeApp_Tools::QtCatchCorbaException(e); - isFailed = true; - } +//================================================================================= +// function : onCompute +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::onCompute() +{ + bool hasSelfInte = false; + QString anErrMsg(""); - if (!anOper->IsDone() && myInters->length() == 0) { - aMsg += tr(anOper->GetErrorCode()); - myGrp->TextView1->setText(aMsg); - return; - } - else if (isFailed) { - aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED"); - myGrp->TextView1->setText(aMsg); + if (!findSelfIntersections(hasSelfInte, anErrMsg)) { + myTextView->setText(anErrMsg); return; } - // Status - if (isGood) { - aMsg += tr("GEOM_NO_SELF_INTERSECTIONS"); - } - else { + // Status and apply buttons + QString aMsg(""); + + if (hasSelfInte) { aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND"); + buttonOk()->setEnabled(true); + buttonApply()->setEnabled(true); + } else { + aMsg += tr("GEOM_NO_SELF_INTERSECTIONS"); } - if (!anOper->IsDone()) { + if (!anErrMsg.isEmpty()) { aMsg += "\n\n"; - aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_ERRORS"); + aMsg += anErrMsg; } - myGrp->TextView1->setText(aMsg); + myTextView->setText(aMsg); // Pairs - QStringList aErrList; - QString aErrStr (""); + QStringList anInteList; + QString anInteStr (""); + int nbPairs = myInters->length()/2; + for (int i = 1; i <= nbPairs; i++) { - aErrStr = "Intersection # "; - aErrStr += QString::number(i); - aErrList.append(aErrStr); + anInteStr = "Intersection # "; + anInteStr += QString::number(i); + anInteList.append(anInteStr); + } + + myInteList->addItems(anInteList); + myComputeButton->setEnabled(false); +} + +//================================================================================= +// function : ActivateThisDialog +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + + LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr(); + if ( aSel ) + connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + activateSelection(); + DISPLAY_PREVIEW_MACRO +} + +//================================================================================= +// function : DeactivateActiveDialog() +// purpose : public slot to deactivate if active +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::DeactivateActiveDialog() +{ + GEOMBase_Skeleton::DeactivateActiveDialog(); +} + +//================================================================================= +// function : activateSelection +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::activateSelection() +{ + globalSelection(GEOM_ALLSHAPES); +} + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::ClickOnOk() +{ + if ( ClickOnApply() ) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::ClickOnApply() +{ + if ( !onAccept() ) + return false; + + initName(); + return true; +} + +//================================================================================= +// function : extractPrefix +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::extractPrefix() const +{ + return true; +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr MeasureGUI_CheckSelfIntersectionsDlg::createOperation() +{ + return getGeomEngine()->GetIMeasureOperations( getStudyId() ); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::isValid( QString& ) +{ + return !myObj->_is_nil(); +} + +//================================================================================= +// function : SetEditCurrentArgument +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::SetEditCurrentArgument() +{ + myEditObjName->setFocus(); + SelectionIntoArgument(); +} + +//================================================================================= +// function : SelectionIntoArgument +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::SelectionIntoArgument() +{ + // Clear the dialog. + clear(); + myObj = GEOM::GEOM_Object::_nil(); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil(); + + if (aSelList.Extent() > 0) { + aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() ); + } + + if (aSelectedObject->_is_nil()) { + myEditObjName->setText(""); + return; + } + + myObj = aSelectedObject; + myEditObjName->setText(GEOMBase::GetName(myObj)); +} + +//================================================================================= +// function : enterEvent +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::enterEvent(QEvent *) +{ + if ( !mainFrame()->GroupConstructors->isEnabled() ) + ActivateThisDialog(); +} + +//================================================================================= +// function : findSelfIntersections +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::findSelfIntersections + (bool &HasSelfInte, QString &theErrMsg) +{ + if (myObj->_is_nil()) { + return false; + } + + GEOM::GEOM_IMeasureOperations_var anOper = + GEOM::GEOM_IMeasureOperations::_narrow(getOperation()); + bool isOK = true; + int nbPairs = 0; + int aLevel = myLevelBox->currentIndex(); + + try { + HasSelfInte = !anOper->CheckSelfIntersections(myObj, aLevel, myInters); + nbPairs = myInters->length()/2; + + if (nbPairs*2 != myInters->length()) { + isOK = false; + } + } + catch (const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); + isOK = false; + } + + if (!anOper->IsDone()) { + if (myInters->length() == 0) { + theErrMsg = tr(anOper->GetErrorCode()); + isOK = false; + } else { + // Valid case. Display all computed self-intersections + theErrMsg = tr("GEOM_CHECK_SELF_INTERSECTIONS_ERRORS"); + } + } else if (!isOK) { + theErrMsg = tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED"); } - myGrp->ListBox1->addItems(aErrList); + return isOK; } //================================================================================= -// function : onErrorsListSelectionChanged +// function : onInteListSelectionChanged // purpose : //================================================================================= -void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged() +void MeasureGUI_CheckSelfIntersectionsDlg::onInteListSelectionChanged() { erasePreview(); - int aCurItem = myGrp->ListBox1->currentRow(); + int aCurItem = myInteList->currentRow(); + if (aCurItem < 0) return; - //int nbPairs = myInters->length()/2; - QStringList aSubShapeList; TopoDS_Shape aSelShape; if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) { @@ -210,8 +462,8 @@ void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged() if (!aType.isEmpty()) aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2 + 1])); } - myGrp->ListBox2->clear(); - myGrp->ListBox2->addItems(aSubShapeList); + myShapeList->clear(); + myShapeList->addItems(aSubShapeList); } //================================================================================= @@ -223,14 +475,14 @@ void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged() erasePreview(); // Current pair - int aErrCurItem = myGrp->ListBox1->currentRow(); + int aErrCurItem = myInteList->currentRow(); if (aErrCurItem < 0) return; // Selected IDs QList aIds; - for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) { - if (myGrp->ListBox2->item(i)->isSelected()) + for (int i = 0, n = myShapeList->count(); i < n; i++) { + if (myShapeList->item(i)->isSelected()) aIds.append(i); } if (aIds.count() < 1) @@ -259,3 +511,82 @@ void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged() } } } + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::execute(ObjectList& objects) +{ + bool hasSelfInte; + QString anErrMsg; + + if (!findSelfIntersections(hasSelfInte, anErrMsg)) { + return false; + } + + const int aNbInteSelected = myInteList->selectedItems().size(); + const bool isPublishAllInte = (aNbInteSelected < 1); + const bool isPublishAllShapes = + (aNbInteSelected != 1 || myShapeList->selectedItems().empty()); + int i; + const int n = myInteList->count(); + TColStd_IndexedMapOfInteger aMapIndex; + + // Collect the map of indices. + for (i = 0; i < n; i++) { + if (isPublishAllInte) { + // Collect the both of two indices. + aMapIndex.Add(myInters[i*2]); + aMapIndex.Add(myInters[i*2 + 1]); + } else if (myInteList->item(i)->isSelected()) { + if (isPublishAllShapes) { + // Collect the both of two indices. + aMapIndex.Add(myInters[i*2]); + aMapIndex.Add(myInters[i*2 + 1]); + } else if (myShapeList->count() == 2) { + // Collect only selected items. + if (myShapeList->item(0)->isSelected()) { + aMapIndex.Add(myInters[i*2]); + } + if (myShapeList->item(1)->isSelected()) { + aMapIndex.Add(myInters[i*2 + 1]); + } + } + } + } + + // Create objects. + GEOM::ListOfLong_var anArray = new GEOM::ListOfLong; + const int aNbShapes = aMapIndex.Extent(); + + anArray->length(aNbShapes); + + for (i = 1; i <= aNbShapes; i++) { + anArray[i - 1] = aMapIndex.FindKey(i); + } + + if (myShapesOper->_is_nil()) { + myShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId()); + } + + GEOM::ListOfGO_var aList = myShapesOper->MakeSubShapes(myObj, anArray); + const int aNbObj = aList->length(); + + for (i = 0; i < aNbObj; i++) { + objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); + } + + return true; +} + +//================================================================ +// Function : getFather +// Purpose : Get father object for object to be added in study +// (called with addInStudy method) +//================================================================ +GEOM::GEOM_Object_ptr MeasureGUI_CheckSelfIntersectionsDlg::getFather + (GEOM::GEOM_Object_ptr) +{ + return myObj; +} diff --git a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h index e22346439..e9400be2d 100644 --- a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h +++ b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h @@ -26,38 +26,70 @@ #ifndef MEASUREGUI_CHECKSELFINTERDLG_H #define MEASUREGUI_CHECKSELFINTERDLG_H -#include +#include + +class QComboBox; +class QListWidget; +class QTextBrowser; -class MeasureGUI_1Sel1TextView2ListBox; //================================================================================= // class : MeasureGUI_CheckSelfIntersectionsDlg // purpose : //================================================================================= -class MeasureGUI_CheckSelfIntersectionsDlg : public MeasureGUI_Skeleton +class MeasureGUI_CheckSelfIntersectionsDlg : public GEOMBase_Skeleton { Q_OBJECT public: + MeasureGUI_CheckSelfIntersectionsDlg(GeometryGUI*, QWidget*); ~MeasureGUI_CheckSelfIntersectionsDlg(); protected: - // redefined from GEOMBase_Helper and MeasureGUI_Skeleton - virtual void processObject(); + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid(QString &); + virtual bool execute(ObjectList &); + virtual bool extractPrefix() const; + virtual GEOM::GEOM_Object_ptr getFather (GEOM::GEOM_Object_ptr); private slots: - void onErrorsListSelectionChanged(); + + void onInteListSelectionChanged(); void onSubShapesListSelectionChanged(); + void clear(); + void onCompute(); + void ClickOnOk(); + bool ClickOnApply(); + void ActivateThisDialog(); + void DeactivateActiveDialog(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); private: + void Init(); + void activateSelection(); + void enterEvent(QEvent *); + bool findSelfIntersections + (bool &HasSelfInte, + QString &theErrMsg); private: - MeasureGUI_1Sel1TextView2ListBox* myGrp; + QTextBrowser *myTextView; + QPushButton *mySelButton; + QLineEdit *myEditObjName; + QComboBox *myLevelBox; + QPushButton *myComputeButton; + QListWidget *myInteList; + QListWidget *myShapeList; + GEOM::GEOM_Object_var myObj; GEOM::ListOfLong_var myInters; + GEOM::GEOM_IShapesOperations_var myShapesOper; + }; #endif // MEASUREGUI_CHECKSELFINTERDLG_H