From c7917bada8643db80254fe2a3b3a91d25548b484 Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 17 Oct 2014 12:14:13 +0000 Subject: [PATCH] First implementation of automatic mode of regions creation in the calculation case dialog. --- src/HYDROData/HYDROData_CalculationCase.cxx | 9 + src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 228 ++++++++++++++++---- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 33 ++- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 66 +++++- src/HYDROGUI/HYDROGUI_CalculationOp.h | 15 +- src/HYDROGUI/HYDROGUI_ListModel.cxx | 45 +++- src/HYDROGUI/HYDROGUI_ListModel.h | 7 + src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx | 101 ++++++++- src/HYDROGUI/HYDROGUI_OrderedListWidget.h | 14 +- src/HYDROGUI/HYDROGUI_PriorityWidget.cxx | 84 ++++++++ src/HYDROGUI/HYDROGUI_PriorityWidget.h | 60 ++++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 38 +++- 13 files changed, 642 insertions(+), 60 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_PriorityWidget.cxx create mode 100644 src/HYDROGUI/HYDROGUI_PriorityWidget.h diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 732e218a..005ac412 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -1089,6 +1089,9 @@ void HYDROData_CalculationCase::ClearRules() { TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); HYDROData_PriorityQueue::ClearRules( aRulesLab ); + + // Indicate model of the need to update splitting + SetToUpdate( true ); } void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1, @@ -1098,6 +1101,9 @@ void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theO { TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules ); HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType ); + + // Indicate model of the need to update splitting + SetToUpdate( true ); } QString HYDROData_CalculationCase::DumpRules() const @@ -1110,6 +1116,9 @@ void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode ) { TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode ); TDataStd_Integer::Set( aModeLab, ( int ) theMode ); + + // Indicate model of the need to update splitting + SetToUpdate( true ); } HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index a3acda81..fc5dfac4 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -99,6 +99,7 @@ set(PROJECT_HEADERS HYDROGUI_OrderedListWidget.h HYDROGUI_ListSelector.h HYDROGUI_ZLayers.h + HYDROGUI_PriorityWidget.h ) QT4_WRAP_CPP(PROJECT_HEADERS_MOC ${PROJECT_HEADERS}) @@ -200,6 +201,7 @@ set(PROJECT_SOURCES HYDROGUI_ListSelector.cxx HYDROGUI_ZLayers.cxx HYDROGUI_ZLayers2.cxx + HYDROGUI_PriorityWidget.cxx ) add_definitions( diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index ba31ad82..a8c978db 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -26,11 +26,14 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_DataBrowser.h" #include "HYDROGUI_DataModel.h" +#include "HYDROGUI_ListSelector.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_DataObject.h" #include "HYDROGUI_NameValidator.h" #include "HYDROGUI_Region.h" #include "HYDROGUI_Zone.h" +#include "HYDROGUI_OrderedListWidget.h" +#include "HYDROGUI_PriorityWidget.h" #include #include @@ -45,9 +48,12 @@ #include #include +#include #include #include +#include +#include #include #include #include @@ -55,10 +61,13 @@ #include #include #include +#include +#include +#include #include +#include #include -#include -#include + HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_Wizard( theModule, theTitle ) @@ -75,16 +84,26 @@ HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg() void HYDROGUI_CalculationDlg::reset() { myObjectName->clear(); - myGeomObjects->clear(); + HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList; + myGeomObjects->setObjects(anObject2VisibleList); myPolylineName->clear(); myAvailableGeomObjects->clear(); + + // Activate the automatic mode + setMode( HYDROData_CalculationCase::AUTOMATIC ); } QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); - // Calculation name + // Splitter + mySplitter = new QSplitter(Qt::Vertical); + + // Top of the page + QWidget* aTopContainer = new QWidget; + + // calculation name myObjectName = new QLineEdit( aPage ); myValidator = new HYDROGUI_NameValidator(module(), myObjectName); myObjectName->setValidator( myValidator ); @@ -92,32 +111,49 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { connect( myValidator, SIGNAL( emptyName() ), SLOT( onEmptyName() ) ); connect( myValidator, SIGNAL( alreadyExists( QString ) ), SLOT( onAlreadyExists( QString ) ) ); + // polyline name myPolylineName = new QComboBox( aPage ); connect( myPolylineName, SIGNAL( activated( const QString & ) ), SIGNAL( boundarySelected( const QString & ) ) ); - myGeomObjects = new QListWidget( aPage ); - myGeomObjects->setSelectionMode( QListWidget::ExtendedSelection ); - myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); - myGeomObjects->setViewMode( QListWidget::ListMode ); - myGeomObjects->setSortingEnabled( true ); + // names labels + QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage ); + QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage ); + + // mode selector (auto/manual) + QGroupBox* aModeGroup = new QGroupBox( tr( "MODE" ) ); + QRadioButton* aManualRB = new QRadioButton( tr( "MANUAL" ), mainFrame() ); + QRadioButton* anAutoRB = new QRadioButton( tr( "AUTO" ), mainFrame() ); + + myModeButtons = new QButtonGroup( mainFrame() ); + myModeButtons->addButton( anAutoRB, HYDROData_CalculationCase::AUTOMATIC ); + myModeButtons->addButton( aManualRB, HYDROData_CalculationCase::MANUAL ); + + QBoxLayout* aModeSelectorLayout = new QHBoxLayout; + aModeSelectorLayout->setMargin( 5 ); + aModeSelectorLayout->setSpacing( 5 ); + aModeSelectorLayout->addWidget( anAutoRB ); + aModeSelectorLayout->addWidget( aManualRB ); + aModeGroup->setLayout( aModeSelectorLayout ); + + // geometry objects + QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ) ); + myGeomObjects = new HYDROGUI_OrderedListWidget( aPage, 16 ); + myGeomObjects->setHiddenObjectsShown(true); + myGeomObjects->setVisibilityIconShown(false); + myGeomObjects->setContentsMargins(QMargins()); + + // included geometry objects + QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ) ); myAvailableGeomObjects = new QListWidget( aPage ); myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection ); myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); myAvailableGeomObjects->setViewMode( QListWidget::ListMode ); myAvailableGeomObjects->setSortingEnabled( true ); - connect( myGeomObjects, SIGNAL( itemSelectionChanged() ), - SIGNAL( objectsSelected() ) ); - - QFrame* anObjectsFrame = new QFrame( aPage ); - QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame ); - anObjsLayout->setMargin( 5 ); - anObjsLayout->setSpacing( 5 ); - anObjectsFrame->setLayout( anObjsLayout ); - - QFrame* aBtnsFrame = new QFrame( anObjectsFrame ); + // buttons + QFrame* aBtnsFrame = new QFrame; QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame ); aBtnsLayout->setMargin( 5 ); aBtnsLayout->setSpacing( 5 ); @@ -125,38 +161,77 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame ); QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame ); - // Fill the butons frame with two buttons + // fill the butons frame with two buttons aBtnsLayout->addWidget( anAddBtn ); aBtnsLayout->addWidget( aRemoveBtn ); aBtnsLayout->addStretch( 1 ); - - QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_OBJECTS" ), anObjectsFrame ); - QLabel* anObjectsLabel = new QLabel( tr( "CALCULATION_REFERENCE_OBJECTS" ), anObjectsFrame ); - - // Fill the objects frame with two lists, two labels and with buttons frame + + // top of the page layout + + // objects frame + QFrame* anObjectsFrame = new QFrame( aPage ); + anObjectsFrame->setFrameStyle( QFrame::Panel | QFrame::Raised ); + QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame ); + anObjsLayout->setMargin( 5 ); + anObjsLayout->setSpacing( 5 ); + anObjectsFrame->setLayout( anObjsLayout ); + + // fill the objects frame with two lists, two labels and with buttons frame anObjsLayout->addWidget( anObjectsLabel, 0, 0, Qt::AlignHCenter ); anObjsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter ); anObjsLayout->addWidget( myAvailableGeomObjects, 1, 0, Qt::AlignHCenter ); anObjsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter ); anObjsLayout->addWidget( myGeomObjects, 1, 2, Qt::AlignHCenter ); - - - QLabel* aNameLabel = new QLabel( tr( "NAME" ), aPage ); - QLabel* aLimitsLabel = new QLabel( tr( "LIMITS" ), aPage ); - - // Fill the page - QGridLayout* aPageLayout = new QGridLayout( aPage ); + + // fill the top of the page + QGridLayout* aTopLayout = new QGridLayout; + aTopLayout->setMargin( 5 ); + aTopLayout->setSpacing( 5 ); + aTopLayout->setVerticalSpacing( 10 ); + aTopLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter ); + aTopLayout->addWidget( myObjectName, 0, 1 ); + aTopLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter ); + aTopLayout->addWidget( myPolylineName, 1, 1 ); + aTopLayout->addWidget( aModeGroup, 2, 0, 1, 2 ); + aTopLayout->addWidget( anObjectsFrame, 3, 0, 1, 2, Qt::AlignHCenter ); + + aTopContainer->setLayout( aTopLayout ); + + // add the top of the page to the splitter + mySplitter->insertWidget(0, aTopContainer); + mySplitter->setStretchFactor(0, 2); + + // Bottom of the page + myPriorityWidget = new HYDROGUI_PriorityWidget( mainFrame() ); + + QGroupBox* aPriorityGroup = new QGroupBox( tr( "PRIORITY" ) ); + QBoxLayout* aPriorityLayout = new QHBoxLayout; + aPriorityLayout->setMargin( 5 ); + aPriorityLayout->setSpacing( 5 ); + aPriorityLayout->addWidget( myPriorityWidget ); + aPriorityGroup->setLayout( aPriorityLayout ); + + // add the bottom of the page to the splitter + mySplitter->insertWidget(1, aPriorityGroup); + mySplitter->setStretchFactor(1, 1); + + // Page layout + QVBoxLayout* aPageLayout = new QVBoxLayout; aPageLayout->setMargin( 5 ); aPageLayout->setSpacing( 5 ); - aPageLayout->setVerticalSpacing( 10 ); - aPageLayout->addWidget( aNameLabel, 0, 0, Qt::AlignHCenter ); - aPageLayout->addWidget( myObjectName, 0, 1 ); - aPageLayout->addWidget( aLimitsLabel, 1, 0, Qt::AlignHCenter ); - aPageLayout->addWidget( myPolylineName, 1, 1 ); - aPageLayout->addWidget( anObjectsFrame, 2, 0, 1, 2, Qt::AlignHCenter ); + aPageLayout->addWidget( mySplitter ); aPage->setLayout( aPageLayout ); + // Create selector + if ( module() ) { + HYDROGUI_ListSelector* aListSelector = + new HYDROGUI_ListSelector( myGeomObjects, module()->getApp()->selectionMgr() ); + aListSelector->setAutoBlock( true ); + } + + // Connections + connect( myModeButtons, SIGNAL( buttonClicked( int ) ), SIGNAL( changeMode( int ) ) ); connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addObjects() ) ); connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeObjects() ) ); @@ -266,7 +341,7 @@ bool HYDROGUI_CalculationDlg::acceptCurrent() const { QString anErrorMsg; - if ( myGeomObjects->count() == 0 ) + if ( false /*myGeomObjects->count() == 0*/ ) { anErrorMsg = tr( "EMPTY_GEOMETRY_OBJECTS" ); } @@ -418,12 +493,35 @@ void moveItems( QListWidget* theSource, QListWidget* theDest, const QStringList& void HYDROGUI_CalculationDlg::includeGeomObjects( const QStringList& theObjects ) { - moveItems( myAvailableGeomObjects, myGeomObjects, theObjects ); + HYDROGUI_ListModel::Object2VisibleList anObjectsToInclude; + QList aFoundItems; + foreach ( const QString& anObjName, theObjects ) { + // Hide the object in the available objects list + aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly ); + foreach ( QListWidgetItem* anItem, aFoundItems ) { + anItem->setHidden( true ); + } + + // Add the object to the list of included objects + Handle(HYDROData_Entity) anObject = + HYDROGUI_Tool::FindObjectByName( module(), anObjName ); + myGeomObjects->addObject( HYDROGUI_ListModel::Object2Visible( anObject, true ) ); + } } void HYDROGUI_CalculationDlg::excludeGeomObjects( const QStringList& theObjects ) { - moveItems( myGeomObjects, myAvailableGeomObjects, theObjects ); + QList aFoundItems; + foreach ( const QString& anObjName, theObjects ) { + // Set visible the object in the available objects list + aFoundItems = myAvailableGeomObjects->findItems( anObjName, Qt::MatchExactly ); + foreach ( QListWidgetItem* anItem, aFoundItems ) { + anItem->setHidden( false ); + } + + // Remove the object from the list of included objects + myGeomObjects->removeObjectByName( anObjName ); + } } void HYDROGUI_CalculationDlg::setBoundary( const QString& theObjName ) @@ -470,7 +568,12 @@ QStringList getSelected( QListWidget* theWidget ) QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const { - return getSelected( myGeomObjects ); + return myGeomObjects->getSelectedNames(); +} + +QStringList HYDROGUI_CalculationDlg::getAllGeomObjects() const +{ + return myGeomObjects->getAllNames(); } QStringList HYDROGUI_CalculationDlg::getSelectedAvailableGeomObjects() const @@ -491,7 +594,6 @@ void HYDROGUI_CalculationDlg::setEditedObject( const Handle(HYDROData_Calculatio myBrowser->adjustColumnsWidth(); myBrowser->setAutoUpdate( true ); myBrowser->setUpdateModified( true ); - } HYDROGUI_Zone* HYDROGUI_CalculationDlg::getCurrentZone() const @@ -541,3 +643,43 @@ void HYDROGUI_CalculationDlg::excludeGroups( const QStringList& theObjects ) { moveItems( myGroups, myAvailableGroups, theObjects ); } + +/** + Get creation mode. + @param theMode the mode +*/ +int HYDROGUI_CalculationDlg::getMode() const +{ + return myModeButtons->checkedId(); +} + +/** + Set creation mode. + @param theMode the mode +*/ +void HYDROGUI_CalculationDlg::setMode( int theMode ) +{ + bool isBlocked = myModeButtons->blockSignals( true ); + myModeButtons->button( theMode )->setChecked( true ); + myModeButtons->blockSignals( isBlocked ); + + bool isAuto = ( theMode == HYDROData_CalculationCase::AUTOMATIC ); + + myGeomObjects->setOrderingEnabled( isAuto ); + QWidget* aWidget = mySplitter->widget( 1 ); + if ( aWidget ) { + aWidget->setVisible( isAuto ); + } +} + +/** + Enable/disable zones drag and drop. + @param theIsEnabled if true - zones drag and drop will be enabled +*/ +void HYDROGUI_CalculationDlg::setMoveZonesEnabled( const bool theIsEnabled ) +{ + //TODO: to be reimplemented + foreach ( QTreeView* aView, myBrowser->findChildren() ) { + aView->setDragEnabled ( theIsEnabled ); + } +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index eaf3aa26..e58dfa73 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -27,16 +27,23 @@ #include class HYDROGUI_ObjSelector; +class HYDROGUI_DataBrowser; +class HYDROGUI_NameValidator; +class HYDROGUI_Zone; +class HYDROGUI_OrderedListWidget; +class HYDROGUI_PriorityWidget; + +class SUIT_DataObject; + +class QButtonGroup; class QGroupBox; class QLineEdit; class QListWidget; class QComboBox; class QLabel; +class QSplitter; class QStringList; -class HYDROGUI_DataBrowser; -class HYDROGUI_NameValidator; -class SUIT_DataObject; -class HYDROGUI_Zone; + class HYDROGUI_CalculationDlg : public HYDROGUI_Wizard { @@ -48,22 +55,28 @@ public: void reset(); + int getMode() const; + void setObjectName( const QString& theName ); QString getObjectName() const; void setEditedObject( const Handle(HYDROData_CalculationCase) theCase ); void setAllGeomObjects( const QStringList& theObjects, const QStringList& theObjectsEntries ); + QStringList getAllGeomObjects() const; void setPolylineNames( const QStringList& theObjects, const QStringList& theObjectsEntries ); QStringList getSelectedGeomObjects() const; QStringList getSelectedAvailableGeomObjects() const; QStringList getSelectedGroups() const; QStringList getSelectedAvailableGroups() const; HYDROGUI_Zone* getCurrentZone() const; - + void setAvailableGroups( const QStringList& ); + void setMoveZonesEnabled( const bool theIsEnabled ); + public slots: + void setMode( int theMode ); void setBoundary( const QString& theObjName ); void includeGeomObjects( const QStringList& theObjects ); void excludeGeomObjects( const QStringList& theObjects ); @@ -88,6 +101,8 @@ public slots: SUIT_DataObject* theTargetParent, int theTargetRow, Qt::DropAction theDropAction ); signals: + void changeMode( int theMode ); + void addObjects(); void removeObjects(); void objectsSelected(); @@ -112,14 +127,20 @@ private: QWizardPage* createGroupsPage(); QWizardPage* createZonesPage(); + QSplitter* mySplitter; + QGroupBox* myObjectNameGroup; QLineEdit* myObjectName; HYDROGUI_NameValidator* myValidator; QComboBox* myPolylineName; + QButtonGroup* myModeButtons; + QListWidget* myAvailableGeomObjects; - QListWidget* myGeomObjects; + HYDROGUI_OrderedListWidget* myGeomObjects; + + HYDROGUI_PriorityWidget* myPriorityWidget; QListWidget* myAvailableGroups; QListWidget* myGroups; diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index f3b4351c..f6238938 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -133,6 +133,7 @@ void HYDROGUI_CalculationOp::startOperation() myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); if ( !myEditedObject.IsNull() ) { + aPanel->setMode( myEditedObject->GetAssignmentMode() ); anObjectName = myEditedObject->GetName(); aPolylineObj = myEditedObject->GetBoundaryPolyline(); if ( aPolylineObj.IsNull() ) @@ -154,7 +155,8 @@ void HYDROGUI_CalculationOp::startOperation() { myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) ); - myEditedObject->SetName(anObjectName); + myEditedObject->SetName( anObjectName ); + myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() ); } aPanel->setObjectName( anObjectName ); @@ -203,6 +205,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() ); // Connect signals and slots + connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) ); connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) ); connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) ); @@ -485,7 +488,32 @@ bool HYDROGUI_CalculationOp::confirmRegionsChange() const // If there are already defined zones then ask a user to confirm zones recalculation isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(), tr( "REGIONS_CHANGED" ), - tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION" ), + 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 + 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( "MODE_CHANGED" ), + tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes ); } @@ -585,7 +613,23 @@ void HYDROGUI_CalculationOp::onNext( const int theIndex ) // At first we must to update the case name because of // automatic names generation for regions and zones myEditedObject->SetName( aNewCaseName ); - + + // Set objects in the specified order + int aMode = aPanel->getMode(); + if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) { + 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 ); + } + } + aPanel->setMoveZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL ); + if ( myEditedObject->IsMustBeUpdated() ) { myShowZones = true; @@ -880,3 +924,19 @@ void HYDROGUI_CalculationOp::onRemoveGroups() aPanel->excludeGroups( aSelectedList ); } + +void HYDROGUI_CalculationOp::onChangeMode( int theMode ) +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + if ( !confirmModeChange() ) { + aPanel->setMode( myEditedObject->GetAssignmentMode() ); + return; + } + + myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode ); + aPanel->setMode( theMode ); +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 81c19c61..d64b483e 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -58,6 +58,13 @@ protected: void setAvailableGroups(); protected slots: + + /** + * Change the creation mode. + * @param theMode the mode to set + */ + void onChangeMode( int theMode ); + /** * Add geometry objects selected in the module browser to the calculation case. */ @@ -120,11 +127,17 @@ private: QStringList& theNames, QStringList& theEntries ) const; /** - * Ask user to confirm splitting zones recalculation. + * 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; + private: bool myIsEdit; bool myShowZones; diff --git a/src/HYDROGUI/HYDROGUI_ListModel.cxx b/src/HYDROGUI/HYDROGUI_ListModel.cxx index 24e3fe8f..e6deaf42 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.cxx +++ b/src/HYDROGUI/HYDROGUI_ListModel.cxx @@ -37,7 +37,7 @@ const QString OBJ_LIST_MIME_TYPE = "application/hydro.objects.list"; @param theParent the parent object */ HYDROGUI_ListModel::HYDROGUI_ListModel( QObject* theParent ) - : QAbstractListModel( theParent ) + : QAbstractListModel( theParent ), myIsDecorationEnabled( true ) { // Get resource manager SUIT_ResourceMgr* aResMgr = 0; @@ -89,8 +89,8 @@ QVariant HYDROGUI_ListModel::data( const QModelIndex &theIndex, int theRole ) co case Qt::DecorationRole: { - if( aColumn==0 && aRow >=0 && aRow < myObjects.count() ) - { + if( myIsDecorationEnabled && + aColumn==0 && aRow >=0 && aRow < myObjects.count() ) { bool isVisible = isObjectVisible( aRow ); if( isVisible ) return myEye; @@ -152,6 +152,36 @@ HYDROGUI_ListModel::ObjectList HYDROGUI_ListModel::getObjects() const return anObjects; } +/** + Add the object to the end of the list. + @param theObjects the pair (object; visibility) +*/ +void HYDROGUI_ListModel::addObject( const Object2Visible& theObject ) +{ + myObjects << theObject; + + reset(); +} + +/** + Remove the object from the list. + @param theObjectName the name of the object to remove +*/ +void HYDROGUI_ListModel::removeObjectByName( const QString& theObjectName ) +{ + Object2Visible anItem; + foreach( anItem, myObjects ) { + if ( anItem.first->GetName() == theObjectName ) { + break; + } + } + + myObjects.removeAll(anItem); + + reset(); +} + + /** Check if the object is visible. @param theIndex the object index @@ -453,3 +483,12 @@ bool HYDROGUI_ListModel::isDragAndDropAllowed( const QList& theItems, return isAllowed; } + +/** + Enable/disable decoration (eye icon). + @param theIsToEnable if true - the decoration will be enabled +*/ +void HYDROGUI_ListModel::setDecorationEnabled( const bool theIsToEnable ) +{ + myIsDecorationEnabled = theIsToEnable; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ListModel.h b/src/HYDROGUI/HYDROGUI_ListModel.h index 12ca7f71..ea65f808 100644 --- a/src/HYDROGUI/HYDROGUI_ListModel.h +++ b/src/HYDROGUI/HYDROGUI_ListModel.h @@ -69,11 +69,16 @@ public: void setObjects( const Object2VisibleList& theObjects ); ObjectList getObjects() const; + void addObject( const Object2Visible& theObject ); + void removeObjectByName( const QString& theObjectName ); + bool move( const int theItem, const OpType theType, bool theIsVisibleOnly, const int theDropItem = -1 ); bool move( const QList& theItems, const OpType theType, bool theIsVisibleOnly, const int theDropItem = -1 ); + void setDecorationEnabled( const bool theIsToEnable ); + protected: bool isObjectVisible( int theIndex ) const; bool isDragAndDropAllowed( const QList& theItems, const int theDropItem ) const; @@ -83,6 +88,8 @@ private: Object2VisibleList myObjects; QPixmap myEmpty, myEye; + + bool myIsDecorationEnabled; }; #endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx index 1308378f..b4bf9a1b 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.cxx @@ -37,12 +37,14 @@ /** Constructor. @param theParent the parent widget + @param theIconSize the icon size for arrow buttons */ -HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) +HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent, int theArrowIconSize ) : QWidget( theParent ) { // Main layout QHBoxLayout* aMainLayout = new QHBoxLayout( this ); + aMainLayout->setMargin( 0 ); aMainLayout->setSpacing( 5 ); // List view @@ -68,7 +70,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); myTop = new QPushButton( this ); myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) ); - myTop->setIconSize( QSize( 32, 32 ) ); + myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) ); myTop->setToolTip( tr( "TOP_TLT" ) ); myUp = new QPushButton( this ); myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) ); @@ -112,6 +114,7 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent ) // Initialize setHiddenObjectsShown( true ); + setVisibilityIconShown( true ); } /** @@ -149,6 +152,30 @@ QList HYDROGUI_OrderedListWidget::getObjects() const return anObjects; } +/** + Add the object to the end of the list. + @param theObjects the pair (object; visibility) +*/ +void HYDROGUI_OrderedListWidget::addObject( const HYDROGUI_ListModel::Object2Visible& theObject ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->addObject(theObject); + } +} + +/** + Remove the object from the list. + @param theObjectName the name of the object to remove +*/ +void HYDROGUI_OrderedListWidget::removeObjectByName( const QString& theObjectName ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->removeObjectByName(theObjectName); + } +} + /** Set whether the hidden objects are presented in the list. @param theIsToShow if true - the hidden objects will be shown in the list @@ -162,6 +189,18 @@ void HYDROGUI_OrderedListWidget::setHiddenObjectsShown( const bool theIsToShow ) aFilterModel->setFilterRegExp( anExpr ); } +/** + Set whether the visibility icon (eye icon) are presented in the list. + @param theIsToShow if true - the eye icon will be shown in the list +*/ +void HYDROGUI_OrderedListWidget::setVisibilityIconShown( const bool theIsToShow ) +{ + HYDROGUI_ListModel* aModel = getSourceModel(); + if( aModel ) { + aModel->setDecorationEnabled( theIsToShow ); + } +} + /** Get entries of the selected objects. @return the list of entries @@ -223,6 +262,48 @@ void HYDROGUI_OrderedListWidget::setSelectedEntries( const QStringList& theEntri } } +/** + Get names of the selected objects. + @return the list of names +*/ +QStringList HYDROGUI_OrderedListWidget::getSelectedNames() const +{ + QStringList aNames; + + QSortFilterProxyModel* aFilterModel = + dynamic_cast( myList->model() ); + if ( aFilterModel ) { + HYDROGUI_ListModel* aSourceModel = + dynamic_cast( aFilterModel->sourceModel() ); + if ( aSourceModel ) { + QModelIndexList aSelectedIndexes = myList->selectionModel()->selectedIndexes(); + foreach ( const QModelIndex& anIndex, aSelectedIndexes ) { + QModelIndex aSourceIndex = aFilterModel->mapToSource( anIndex ); + QString anEntry = aSourceModel->data( aSourceIndex, Qt::DisplayRole ).toString(); + aNames << anEntry; + } + } + } + + return aNames; +} + +/** + Get names of all objects. + @return the list of names +*/ +QStringList HYDROGUI_OrderedListWidget::getAllNames() const +{ + QStringList aNames; + + + foreach ( const Handle(HYDROData_Entity)& anObject, getObjects() ) { + aNames << anObject->GetName(); + } + + return aNames; +} + /** Slot called on top, up, down and bottom button click. @param theType the move operation type @@ -259,4 +340,20 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const } return aSourceModel; +} + +/** + Enable/disable ordering (i.e. enable/disable arrow buttons and drag and drop). + @param theIsToEnable if true - ordering will bw enabled +*/ +void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable ) +{ + // enable/disable arrow buttons + myTop->setEnabled( theIsToEnable ); + myUp->setEnabled( theIsToEnable ); + myDown->setEnabled( theIsToEnable ); + myBottom->setEnabled( theIsToEnable ); + + // enable/disable drag and drop + myList->setDragEnabled( theIsToEnable ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h index e199fb7a..39bf9ebe 100644 --- a/src/HYDROGUI/HYDROGUI_OrderedListWidget.h +++ b/src/HYDROGUI/HYDROGUI_OrderedListWidget.h @@ -42,17 +42,26 @@ class HYDRO_EXPORT HYDROGUI_OrderedListWidget : public QWidget Q_OBJECT public: - HYDROGUI_OrderedListWidget( QWidget* theParent ); + HYDROGUI_OrderedListWidget( QWidget* theParent, int theArrowIconSize = 32 ); virtual ~HYDROGUI_OrderedListWidget(); void setObjects( const HYDROGUI_ListModel::Object2VisibleList& theObjects ); HYDROGUI_ListModel::ObjectList getObjects() const; + void addObject( const HYDROGUI_ListModel::Object2Visible& theObject ); + void removeObjectByName( const QString& theObjectName ); + void setHiddenObjectsShown( const bool theIsToShow ); + void setVisibilityIconShown( const bool theIsToShow ); + + void setOrderingEnabled( const bool theIsToEnable ); QStringList getSelectedEntries() const; void setSelectedEntries( const QStringList& theEntries ) const; + QStringList getSelectedNames() const; + QStringList getAllNames() const; + signals: void selectionChanged(); @@ -62,6 +71,8 @@ private slots: private: HYDROGUI_ListModel* getSourceModel() const; + QModelIndexList getSelectedIndexes() const; + private: QListView* myList; ///< the list view QPushButton* myTop; ///< the move on top button @@ -70,6 +81,7 @@ private: QPushButton* myBottom; ///< the move on bottom button bool myIsHiddenObjectsShown; ///< defines whether to include hidden objects in the list + bool myIsVisibilityIconShown; ///< defines whether to show visibility icon (eye icon) }; #endif diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx new file mode 100644 index 00000000..7200311e --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -0,0 +1,84 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "HYDROGUI_PriorityWidget.h" + +#include +#include +#include + + +/** + Constructor. + @param theParent the parent widget +*/ +HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent ) +: QWidget( theParent ) +{ + // Main layout + QVBoxLayout* aMainLayout = new QVBoxLayout( this ); + aMainLayout->setMargin( 0 ); + aMainLayout->setSpacing( 5 ); + + // Buttons + myAdd = new QPushButton( tr( "ADD" ) ); + myRemove = new QPushButton( tr( "REMOVE" ) ); + + // Table view + myTable = new QTableView( this ); + + // Layout + // buttons + QHBoxLayout* aButtonsLayout = new QHBoxLayout(); + aButtonsLayout->addWidget( myAdd ); + aButtonsLayout->addWidget( myRemove ); + aButtonsLayout->addStretch( 1 ); + + // main + aMainLayout->addLayout( aButtonsLayout ); + aMainLayout->addWidget( myTable ); + + // Connections + connect( myAdd, SIGNAL( clicked() ), this, SLOT( onAdd() ) ); + connect( myRemove, SIGNAL( clicked() ), this, SLOT( onRemove() ) ); +} + +/** + Destructor. +*/ +HYDROGUI_PriorityWidget::~HYDROGUI_PriorityWidget() +{ +} + +/** + Adds the new rule. +*/ +void HYDROGUI_PriorityWidget::onAddRule() +{ +} + +/** + Removes the selected rule. +*/ +void HYDROGUI_PriorityWidget::onRemoveRule() +{ +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h new file mode 100644 index 00000000..48d4e737 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef HYDROGUI_PRIORITYWIDGET_H +#define HYDROGUI_PRIORITYWIDGET_H + +#include + +#include + +class QTableView; +class QPushButton; + +/** + * \class HYDROGUI_PriorityWidget + * \brief The class representing widget for tuning of the objects priorities and bathymetry conflicts + * + * The widget represents a table and a set of buttons (add and remove) + * providing the possibility to define priority rules. + */ +class HYDRO_EXPORT HYDROGUI_PriorityWidget : public QWidget +{ + Q_OBJECT + +public: + HYDROGUI_PriorityWidget( QWidget* theParent ); + virtual ~HYDROGUI_PriorityWidget(); + + void setObjects( const QStringList& theObjects ); + +protected slots: + void onAddRule(); + void onRemoveRule(); + +private: + QTableView* myTable; ///< the table view + QPushButton* myAdd; ///< the add rule button + QPushButton* myRemove; ///< the remove rule button +}; + +#endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 02b897a1..fd6a96a4 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -281,6 +281,22 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) EMPTY_GEOMETRY_OBJECTS No one geometry object is selected, should be at least one. + + MODE + Mode + + + AUTO + Auto + + + MANUAL + Manual + + + PRIORITY + Priority + @@ -302,9 +318,17 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) Regions list modification - CONFIRM_SPLITTING_ZONES_RECALCULATION + CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS Case splitting zones already exist and will be recalculated after regions list modification. Do you confirm the recalculation? + + MODE_CHANGED + Change creation mode + + + CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE + Case splitting zones already exist and will be recalculated after mode change. Do you confirm the recalculation? + @@ -2137,4 +2161,16 @@ Polyline should consist from one not closed curve. + + HYDROGUI_PriorityWidget + + ADD + Add + + + REMOVE + Remove + + + -- 2.39.2