From d19b859a9aa18d711e35aad0b425c7c6384139f3 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 21 May 2015 08:58:31 +0300 Subject: [PATCH] refs #542: warning about changed objects order --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 7 +- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 1 + src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 79 ++++++++++++++++----- src/HYDROGUI/HYDROGUI_CalculationOp.h | 24 ++----- src/HYDROGUI/HYDROGUI_ListModel.cxx | 9 ++- src/HYDROGUI/HYDROGUI_ListModel.h | 4 +- src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx | 12 +++- src/HYDROGUI/HYDROGUI_OrderedListWidget.h | 2 + src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++ 9 files changed, 101 insertions(+), 41 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 49d61888..c23683e9 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -738,5 +738,10 @@ void HYDROGUI_CalculationDlg::setRules( const HYDROData_ListOfRules& theRules ) */ void HYDROGUI_CalculationDlg::onOrderChanged() { - myPriorityWidget->setObjects( getGeometryObjects() ); + bool isConfirmed = true; + emit orderChanged( isConfirmed ); + if( isConfirmed ) + myPriorityWidget->setObjects( getGeometryObjects() ); + else + myGeomObjects->undoLastMove(); } diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 3578ec12..a769f3d4 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -108,6 +108,7 @@ signals: void addObjects(); void removeObjects(); void objectsSelected(); + void orderChanged( bool& isConfirmed ); void addGroups(); void removeGroups(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 66b9a89b..ec7c4c83 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -228,6 +228,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) ); connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) ); + connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) ); connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) ); connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) ); //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) ); @@ -518,6 +519,31 @@ bool HYDROGUI_CalculationOp::confirmRegionsChange() const return isConfirmed; } +bool HYDROGUI_CalculationOp::confirmOrderChange() const +{ + // Check if the case is already modified or not + bool isConfirmed = myEditedObject->IsMustBeUpdated(); + if ( !isConfirmed ) + { + // If not modified check if the case has already defined regions with zones + HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions(); + if ( aSeq.Length() > 0 ) + { + // If there are already defined zones then ask a user to confirm zones recalculation + isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "ORDER_CHANGED" ), + tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ) == QMessageBox::Yes ); + } + else + { + isConfirmed = true; // No regions - no zones - nothing to recalculate + } + } + return isConfirmed; +} + bool HYDROGUI_CalculationOp::confirmModeChange() const { // Check if the case is already modified or not @@ -683,27 +709,32 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) // Set parameters for automatic mode int aMode = aPanel->getMode(); - if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) { + if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) + { // Set objects in the specified order - myEditedObject->RemoveGeometryObjects(); - foreach ( const QString& aName, aPanel->getAllGeomObjects() ) { - Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aName ) ); - if ( anObject.IsNull() ) { - continue; + if( myEditedObject->IsMustBeUpdated() ) + { + myEditedObject->RemoveGeometryObjects(); + foreach ( const QString& aName, aPanel->getAllGeomObjects() ) + { + Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aName ) ); + if ( anObject.IsNull() ) + { + continue; + } + myEditedObject->AddGeometryObject( anObject ); } - myEditedObject->AddGeometryObject( anObject ); - } - - // Clear priority rules - //@ASL if ( myEditedObject->GetRulesCount() > 0 ) { - myEditedObject->ClearRules( true ); - //@ASL } - // Set priority rules - foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) { - myEditedObject->AddRule( aRule.Object1, aRule.Priority, - aRule.Object2, aRule.MergeType ); + // Clear priority rules + //@ASL if ( myEditedObject->GetRulesCount() > 0 ) { + myEditedObject->ClearRules( true ); + //@ASL } + // Set priority rules + foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) { + myEditedObject->AddRule( aRule.Object1, aRule.Priority, + aRule.Object2, aRule.MergeType ); + } } } aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL ); @@ -1102,3 +1133,15 @@ void HYDROGUI_CalculationOp::onChangeMode( int theMode ) myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode ); aPanel->setMode( theMode ); } + +void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed ) +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + isConfirmed = confirmOrderChange(); + if( isConfirmed ) + myEditedObject->SetToUpdate( true ); +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 9213bee1..5ae6b3d8 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -115,6 +115,8 @@ protected slots: */ void onBoundarySelected ( const QString & theObjName ); + void onOrderChanged( bool& isConfirmed ); + private: void createPreview(); void closePreview(); @@ -143,24 +145,10 @@ private: float theSaturation = 0.5, float theValue = 0.95 ) const; - /** - * Ask user to confirm splitting zones recalculation after regions list modification. - * \return true if confirmed - */ - bool confirmRegionsChange() const; - - /** - * Ask user to confirm splitting zones recalculation after mode change. - * \return true if confirmed - */ - bool confirmModeChange() const; - - /** - * Ask user to confirm the operation continuation with warning. - * @param theWarning the warning - * \return true if confirmed - */ - bool confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const; + bool confirmRegionsChange() const; + bool confirmModeChange() const; + bool confirmOrderChange() const; + bool confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const; private: bool myIsEdit; diff --git a/src/HYDROGUI/HYDROGUI_ListModel.cxx b/src/HYDROGUI/HYDROGUI_ListModel.cxx index 8c1cb720..b112dd34 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ListModel.cxx @@ -372,6 +372,7 @@ bool HYDROGUI_ListModel::move( const int theItem, const OpType theType, if ( aDestinationIndex >= 0 && aDestinationIndex < myObjects.count() ) { int aDestinationRow = isInsertBefore ? aDestinationIndex : aDestinationIndex + 1; if ( beginMoveRows( QModelIndex(), theItem, theItem, QModelIndex(), aDestinationRow ) ) { + myPrevObjects = myObjects; myObjects.move( theItem, aDestinationIndex ); endMoveRows(); aRes = true; @@ -487,4 +488,10 @@ bool HYDROGUI_ListModel::isDragAndDropAllowed( const QList& theItems, void HYDROGUI_ListModel::setDecorationEnabled( const bool theIsToEnable ) { myIsDecorationEnabled = theIsToEnable; -} \ No newline at end of file +} + +void HYDROGUI_ListModel::undoLastMove() +{ + myObjects = myPrevObjects; + reset(); +} diff --git a/src/HYDROGUI/HYDROGUI_ListModel.h b/src/HYDROGUI/HYDROGUI_ListModel.h index 11fd1dfa..46a8487d 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.h +++ b/src/HYDROGUI/HYDROGUI_ListModel.h @@ -75,6 +75,8 @@ public: void setDecorationEnabled( const bool theIsToEnable ); + void undoLastMove(); + protected: bool isObjectVisible( int theIndex ) const; bool isDragAndDropAllowed( const QList& theItems, const int theDropItem ) const; @@ -82,7 +84,7 @@ protected: private: friend class test_HYDROGUI_ListModel; - Object2VisibleList myObjects; + Object2VisibleList myObjects, myPrevObjects; QPixmap myEmpty, myEye; bool myIsDecorationEnabled; diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index decfd85a..1b551cfc 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -323,7 +323,8 @@ void HYDROGUI_OrderedListWidget::onMove( int theType ) } } - if ( isMoved ) { + if ( isMoved ) + { emit orderChanged(); } } @@ -358,4 +359,11 @@ void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable ) // enable/disable drag and drop myList->setDragEnabled( theIsToEnable ); -} \ No newline at end of file +} + +void HYDROGUI_OrderedListWidget::undoLastMove() +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) + aModel->undoLastMove(); +} diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h index 71913500..d0ac1262 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h @@ -58,6 +58,8 @@ public: QStringList getSelectedNames() const; QStringList getAllNames() const; + void undoLastMove(); + signals: void selectionChanged(); void orderChanged(); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 907037a6..08446e0e 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -337,6 +337,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) REGIONS_CHANGED Regions list modification + + ORDER_CHANGED + Order of objects is changed + CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation? -- 2.39.2