From: skv Date: Tue, 14 Oct 2014 11:06:14 +0000 (+0400) Subject: Implement Apply buttons functionality X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8e43b2d3fa7a479cab25ee99fb5643061ddde80c;p=modules%2Fgeom.git Implement Apply buttons functionality --- diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 89480676b..dfdf40c7e 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -427,6 +427,10 @@ Please, select face, shell or solid and try again GEOM_SELF_INTERSECTIONS_FOUND Some self-intersections detected + + GEOM_SELF_INTERSECTION_NAME + Self_intersection + GEOM_CHECK_SELF_INTERSECTIONS_ERRORS Warning: there were errors during the operation, so the list may be incomplete. diff --git a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx index 11d27b7ef..bc0d93325 100644 --- a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx @@ -24,6 +24,7 @@ // File : MeasureGUI_CheckSelfIntersectionsDlg.cxx #include "MeasureGUI_CheckSelfIntersectionsDlg.h" +#include "MeasureGUI.h" #include "MeasureGUI_Widgets.h" #include @@ -35,6 +36,7 @@ #include #include +#include #include #include @@ -112,11 +114,95 @@ MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg() //================================================================================= void MeasureGUI_CheckSelfIntersectionsDlg::Init() { - connect(myGrp->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged())); - connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged())); - connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), - this, SLOT(SelectionIntoArgument())); + 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(myGrp->PushButton1, SIGNAL(clicked()), + this, SLOT(SetEditCurrentArgument())); + connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), + SLOT(onInteListSelectionChanged())); + connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), + SLOT(onSubShapesListSelectionChanged())); + + 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 ); + activateSelection(); + SelectionIntoArgument(); +} + +//================================================================================= +// 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 : SelectionIntoArgument +// purpose : +//================================================================================= +bool MeasureGUI_CheckSelfIntersectionsDlg::extractPrefix() const +{ + return true; } //================================================================================= @@ -128,6 +214,15 @@ 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 : @@ -166,83 +261,130 @@ void MeasureGUI_CheckSelfIntersectionsDlg::SelectionIntoArgument() myObj = aSelectedObject; myGrp->LineEdit1->setText(GEOMBase::GetName(myObj)); processObject(); + DISPLAY_PREVIEW_MACRO; } //================================================================================= -// function : processObject +// function : enterEvent // purpose : //================================================================================= -void MeasureGUI_CheckSelfIntersectionsDlg::processObject() +void MeasureGUI_CheckSelfIntersectionsDlg::enterEvent(QEvent *) { - myGrp->ListBox1->clear(); - myGrp->ListBox2->clear(); - erasePreview(); + if ( !mainFrame()->GroupConstructors->isEnabled() ) + ActivateThisDialog(); +} - if (myObj->_is_nil()) - return; +//================================================================================= +// 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; - 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); + HasSelfInte = !anOper->CheckSelfIntersections(myObj, myInters); nbPairs = myInters->length()/2; + if (nbPairs*2 != myInters->length()) { - isFailed = true; + isOK = false; } } catch (const SALOME::SALOME_Exception& e) { SalomeApp_Tools::QtCatchCorbaException(e); - isFailed = true; + isOK = false; } - if (!anOper->IsDone() && myInters->length() == 0) { - aMsg += tr(anOper->GetErrorCode()); - myGrp->TextView1->setText(aMsg); - return; + 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"); } - else if (isFailed) { - aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED"); - myGrp->TextView1->setText(aMsg); + + return isOK; +} + +//================================================================================= +// function : processObject +// purpose : +//================================================================================= +void MeasureGUI_CheckSelfIntersectionsDlg::processObject() +{ + disconnect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), this, 0 ); + disconnect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), this, 0 ); + myGrp->ListBox1->clear(); + myGrp->ListBox2->clear(); + connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), + SLOT(onInteListSelectionChanged())); + connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), + SLOT(onSubShapesListSelectionChanged())); + erasePreview(); + + bool hasSelfInte = false; + QString anErrMsg(""); + + if (!findSelfIntersections(hasSelfInte, anErrMsg)) { + myGrp->TextView1->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"); + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); } - if (!anOper->IsDone()) { + if (!anErrMsg.isEmpty()) { aMsg += "\n\n"; - aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_ERRORS"); + aMsg += anErrMsg; } myGrp->TextView1->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); } - myGrp->ListBox1->addItems(aErrList); + myGrp->ListBox1->addItems(anInteList); } //================================================================================= -// function : onErrorsListSelectionChanged +// function : onInteListSelectionChanged // purpose : //================================================================================= -void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged() +void MeasureGUI_CheckSelfIntersectionsDlg::onInteListSelectionChanged() { erasePreview(); int aCurItem = myGrp->ListBox1->currentRow(); + int aNbItems = myGrp->ListBox1->count(); if (aCurItem < 0) return; @@ -312,3 +454,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 = myGrp->ListBox1->selectedItems().size(); + const bool isPublishAllInte = (aNbInteSelected < 1); + const bool isPublishAllShapes = + (aNbInteSelected != 1 || myGrp->ListBox2->selectedItems().empty()); + int i; + const int n = myGrp->ListBox1->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 (myGrp->ListBox1->item(i)->isSelected()) { + if (isPublishAllShapes) { + // Collect the both of two indices. + aMapIndex.Add(myInters[i*2]); + aMapIndex.Add(myInters[i*2 + 1]); + } else if (myGrp->ListBox2->count() == 2) { + // Collect only selected items. + if (myGrp->ListBox2->item(0)->isSelected()) { + aMapIndex.Add(myInters[i*2]); + } + if (myGrp->ListBox2->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 00104a6d9..f7dea1738 100644 --- a/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h +++ b/src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.h @@ -47,25 +47,39 @@ public: protected: // 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); void processObject(); private slots: - void onErrorsListSelectionChanged(); + void onInteListSelectionChanged(); void onSubShapesListSelectionChanged(); + 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; GEOM::GEOM_Object_var myObj; GEOM::ListOfLong_var myInters; + GEOM::GEOM_IShapesOperations_var myShapesOper; };