From 1ac14cb089babc7875dc626724965359dab0c58e Mon Sep 17 00:00:00 2001 From: rkv Date: Wed, 30 Oct 2013 09:55:23 +0000 Subject: [PATCH] Add/remove objects is implemented on the first page of the Calculation Case operation wizard. --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 23 ++---- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 8 +- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 101 +++++++++++++++++++---- src/HYDROGUI/HYDROGUI_CalculationOp.h | 10 +++ 4 files changed, 107 insertions(+), 35 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 1713e060..302efd74 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -129,16 +129,11 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { aZonesLayout->addWidget( myGeomObjects, 1, 1, 2, 1 ); aZonesLayout->addWidget( aBtnsFrame, 2, 0, Qt::AlignHCenter ); - //QBoxLayout* aMainLayout = new QVBoxLayout( aFrame ); - //aMainLayout->setMargin( 0 ); - //aMainLayout->setSpacing( 5 ); - //aMainLayout->addWidget( myObjectNameGroup ); - //aMainLayout->addWidget( anObjectsFrame ); - //aMainLayout->addStretch(); - - //aPage->setLayout( aMainLayout ); aPage->setLayout( aZonesLayout ); + connect( anAddBtn, SIGNAL( clicked() ), this, SIGNAL( addObjects() ) ); + connect( aRemoveBtn, SIGNAL( clicked() ), this, SIGNAL( removeObjects() ) ); + return aPage; } @@ -213,17 +208,11 @@ void HYDROGUI_CalculationDlg::setSelectedGeomObjects( const QStringList& theObje QStringList HYDROGUI_CalculationDlg::getSelectedGeomObjects() const { QStringList aResList; - - for ( int i = 0, n = myGeomObjects->count(); i < n; ++i ) + QList aList = myGeomObjects->selectedItems(); + for ( int i = 0, n = aList.length(); i < n; ++i ) { - QListWidgetItem* aListItem = myGeomObjects->item( i ); - if ( !aListItem ) - continue; - - QString aSelObjName = aListItem->text(); - aResList.append( aSelObjName ); + aResList.append( aList.at( i )->text() ); } - return aResList; } diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 37206ede..aa3dbe53 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -31,6 +31,7 @@ class QGroupBox; class QLineEdit; class QListWidget; class QComboBox; +class QStringList; class HYDROGUI_DataBrowser; class HYDROGUI_NameValidator; @@ -53,9 +54,14 @@ public: void setSelectedGeomObjects( const QStringList& theObjects ); QStringList getSelectedGeomObjects() const; - public slots: +public slots: void onEmptyName(); void onAlreadyExists( QString theName ); + +signals: + void addObjects(); + void removeObjects(); + private: QWizardPage* createObjectsPage(); diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 621d9d75..977b440b 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -84,22 +85,7 @@ void HYDROGUI_CalculationOp::startOperation() if ( !myEditedObject.IsNull() ) { anObjectName = myEditedObject->GetName(); - - HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects(); - HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_Object) aRefbject = - Handle(HYDROData_Object)::DownCast( anIter.Value() ); - if ( aRefbject.IsNull() ) - continue; - - QString aRefObjectName = aRefbject->GetName(); - if ( aRefObjectName.isEmpty() ) - continue; - - aSelectedObjects.append( aRefObjectName ); - } + updateGeomObjectsList(aPanel); } } else @@ -111,11 +97,34 @@ void HYDROGUI_CalculationOp::startOperation() aPanel->setObjectName( anObjectName ); aPanel->setEditedObject( myEditedObject ); - aPanel->setSelectedGeomObjects( aSelectedObjects ); +// aPanel->setSelectedGeomObjects( aSelectedObjects ); createPreview(); } +void HYDROGUI_CalculationOp::updateGeomObjectsList( HYDROGUI_CalculationDlg* thePanel ) const +{ + Handle(HYDROData_Object) anObject; + Handle(HYDROData_Entity) anEntity; + QStringList aList; + // Update the list in the dialog + HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); + for ( ; anIter.More(); anIter.Next() ) + { + anEntity = anIter.Value(); + if ( !anEntity.IsNull() ) + { + anObject = Handle(HYDROData_Object)::DownCast( anEntity ); + if ( !anObject.IsNull() ) + { + aList.append( anObject->GetName() ); + } + } + } + thePanel->setSelectedGeomObjects( aList ); +} + void HYDROGUI_CalculationOp::abortOperation() { closePreview(); @@ -137,10 +146,68 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() ); // Connect signals and slots + connect( aPanel, SIGNAL( addObjects() ), this, SLOT( onAddObjects() ) ); + connect( aPanel, SIGNAL( removeObjects() ), this, SLOT( onRemoveObjects() ) ); return aPanel; } +void HYDROGUI_CalculationOp::onAddObjects() +{ + // Add geometry objects selected in the module browser to the calculation case + Handle(HYDROData_Object) anObject; + Handle(HYDROData_Entity) anEntity; + QStringList aList; + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); + for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + anEntity = aSeq.Value( anIndex ); + if ( !anEntity.IsNull() ) + { + anObject = Handle(HYDROData_Object)::DownCast( anEntity ); + if( !anObject.IsNull() ) + { + if (myEditedObject->AddGeometryObject( anObject )) + { + aList.append( anObject->GetName() ); + } + } + } + } + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) + { + updateGeomObjectsList( aPanel ); + } +} + +void HYDROGUI_CalculationOp::onRemoveObjects() +{ + // Remove selected objects from the calculation case + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( aPanel ) + { + QStringList aList = aPanel->getSelectedGeomObjects(); + Handle(HYDROData_Object) anObject; + Handle(HYDROData_Entity) anEntity; + for (int i = 0; i < aList.length(); i++) + { + anEntity = HYDROGUI_Tool::FindObjectByName( module(), aList.at(i) ); + if ( !anEntity.IsNull() ) + { + anObject = Handle(HYDROData_Object)::DownCast( anEntity ); + if ( !anObject.IsNull() ) + { + myEditedObject->RemoveGeometryObject( anObject ); + } + } + } + updateGeomObjectsList( aPanel ); + } +} + bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index ecdd145d..9735e436 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -33,6 +33,7 @@ class SUIT_ViewManager; class OCCViewer_ViewManager; +class HYDROGUI_CalculationDlg; class HYDROGUI_CalculationOp : public HYDROGUI_Operation { @@ -80,12 +81,21 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); protected slots: + /** + * Add geometry objects selected in the module browser to the calculation case. + */ + void onAddObjects(); + /** + * Remove selected objects from the calculation case. + */ + void onRemoveObjects(); void onSplitZones(); void onLastViewClosed( SUIT_ViewManager* ); private: void createPreview(); void closePreview(); + void updateGeomObjectsList( HYDROGUI_CalculationDlg* thePanel ) const; private: bool myIsEdit; -- 2.39.2