From dd6cdff692e9ce241c2e5eeb11385a05b3ebbcb3 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 17 Dec 2013 06:45:45 +0000 Subject: [PATCH] bug #243: GUI for groups --- src/HYDROGUI/HYDROGUI_CalculationDlg.cxx | 72 ++++++++++++- src/HYDROGUI/HYDROGUI_CalculationDlg.h | 11 +- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 120 ++++++++++++---------- src/HYDROGUI/HYDROGUI_CalculationOp.h | 6 +- src/HYDROGUI/HYDROGUI_Shape.cxx | 4 +- src/HYDROGUI/HYDROGUI_Shape.h | 2 +- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 8 ++ 7 files changed, 160 insertions(+), 63 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 322fc123..da21a508 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -64,6 +64,7 @@ HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, co : HYDROGUI_Wizard( theModule, theTitle ) { addPage( createObjectsPage() ); + addPage( createGroupsPage() ); addPage( createZonesPage() ); } @@ -96,19 +97,19 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { SIGNAL( boundarySelected( const QString & ) ) ); myGeomObjects = new QListWidget( aPage ); - myGeomObjects->setSelectionMode( QListWidget::SingleSelection ); + myGeomObjects->setSelectionMode( QListWidget::ExtendedSelection ); myGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); myGeomObjects->setViewMode( QListWidget::ListMode ); myGeomObjects->setSortingEnabled( true ); myAvailableGeomObjects = new QListWidget( aPage ); - myAvailableGeomObjects->setSelectionMode( QListWidget::SingleSelection ); + myAvailableGeomObjects->setSelectionMode( QListWidget::ExtendedSelection ); myAvailableGeomObjects->setEditTriggers( QListWidget::NoEditTriggers ); myAvailableGeomObjects->setViewMode( QListWidget::ListMode ); myAvailableGeomObjects->setSortingEnabled( true ); - connect( myGeomObjects, SIGNAL( currentTextChanged( const QString & ) ), - SIGNAL( objectSelected( const QString & ) ) ); + connect( myGeomObjects, SIGNAL( itemSelectionChanged() ), + SIGNAL( objectsSelected() ) ); QFrame* anObjectsFrame = new QFrame( aPage ); QGridLayout* anObjsLayout = new QGridLayout( anObjectsFrame ); @@ -162,6 +163,69 @@ QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { return aPage; } +QWizardPage* HYDROGUI_CalculationDlg::createGroupsPage() { + QWizardPage* aPage = new QWizardPage( mainFrame() ); + QFrame* aFrame = new QFrame( aPage ); + + myGroups = new QListWidget( aPage ); + myGroups->setSelectionMode( QListWidget::ExtendedSelection ); + myGroups->setEditTriggers( QListWidget::NoEditTriggers ); + myGroups->setViewMode( QListWidget::ListMode ); + myGroups->setSortingEnabled( true ); + + myAvailableGroups = new QListWidget( aPage ); + myAvailableGroups->setSelectionMode( QListWidget::ExtendedSelection ); + myAvailableGroups->setEditTriggers( QListWidget::NoEditTriggers ); + myAvailableGroups->setViewMode( QListWidget::ListMode ); + myAvailableGroups->setSortingEnabled( true ); + + connect( myGroups, SIGNAL( itemSelectionChanged() ), + SIGNAL( groupsSelected() ) ); + + QFrame* aGroupsFrame = new QFrame( aPage ); + QGridLayout* aGroupsLayout = new QGridLayout( aGroupsFrame ); + aGroupsLayout->setMargin( 5 ); + aGroupsLayout->setSpacing( 5 ); + aGroupsFrame->setLayout( aGroupsLayout ); + + QFrame* aBtnsFrame = new QFrame( aGroupsFrame ); + QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame ); + aBtnsLayout->setMargin( 5 ); + aBtnsLayout->setSpacing( 5 ); + aBtnsFrame->setLayout( aBtnsLayout ); + QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame ); + QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame ); + + // Fill the butons frame with two buttons + aBtnsLayout->addWidget( anAddBtn ); + aBtnsLayout->addWidget( aRemoveBtn ); + aBtnsLayout->addStretch( 1 ); + + QLabel* anIncludedLabel = new QLabel( tr( "INCLUDED_GROUPS" ), aGroupsFrame ); + QLabel* anAvailableLabel = new QLabel( tr( "AVAILABLE_GROUPS" ), aGroupsFrame ); + + // Fill the objects frame with two lists, two labels and with buttons frame + aGroupsLayout->addWidget( anAvailableLabel, 0, 0, Qt::AlignHCenter ); + aGroupsLayout->addWidget( anIncludedLabel, 0, 2, Qt::AlignHCenter ); + aGroupsLayout->addWidget( myAvailableGroups, 1, 0, Qt::AlignHCenter ); + aGroupsLayout->addWidget( aBtnsFrame, 1, 1, Qt::AlignHCenter ); + aGroupsLayout->addWidget( myGroups, 1, 2, Qt::AlignHCenter ); + + // Fill the page + QGridLayout* aPageLayout = new QGridLayout( aPage ); + aPageLayout->setMargin( 5 ); + aPageLayout->setSpacing( 5 ); + aPageLayout->setVerticalSpacing( 10 ); + aPageLayout->addWidget( aGroupsFrame, 0, 0, Qt::AlignHCenter ); + + aPage->setLayout( aPageLayout ); + + connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addGroups() ) ); + connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removeGroups() ) ); + + return aPage; +} + QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.h b/src/HYDROGUI/HYDROGUI_CalculationDlg.h index 43770dc2..414d4af6 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.h +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.h @@ -84,7 +84,12 @@ public slots: signals: void addObjects(); void removeObjects(); - void objectSelected( const QString & theObjName ); + void objectsSelected(); + + void addGroups(); + void removeGroups(); + void groupsSelected(); + void boundarySelected( const QString & theObjName ); void setMergeType( int theMergeType, QString& theBathymetryName ); void createRegion( const QList& theZonesList ); @@ -98,6 +103,7 @@ protected: private: QWizardPage* createObjectsPage(); + QWizardPage* createGroupsPage(); QWizardPage* createZonesPage(); QGroupBox* myObjectNameGroup; @@ -109,6 +115,9 @@ private: QListWidget* myAvailableGeomObjects; QListWidget* myGeomObjects; + QListWidget* myAvailableGroups; + QListWidget* myGroups; + HYDROGUI_DataBrowser* myBrowser; Handle(HYDROData_CalculationCase) myEditedObject; QComboBox* myBathymetryChoice; diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 2dabc9fa..91cbb27e 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -204,7 +204,7 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const // Connect signals and slots connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) ); connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) ); - connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onSplitZones() ) ); + 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* ) ) ); connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) ); @@ -214,8 +214,8 @@ HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const SLOT( onCreateRegion( const QList& ) ) ); connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ), SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) ); - connect( aPanel, SIGNAL( objectSelected( const QString & ) ), - SLOT( onObjectSelected( const QString & ) ) ); + connect( aPanel, SIGNAL( objectsSelected() ), + SLOT( onObjectsSelected() ) ); connect( aPanel, SIGNAL( boundarySelected( const QString & ) ), SLOT( onBoundarySelected( const QString & ) ) ); @@ -261,14 +261,22 @@ void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName ) } } -void HYDROGUI_CalculationOp::onObjectSelected ( const QString & theObjName ) +void HYDROGUI_CalculationOp::onObjectsSelected() { + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + + QStringList aSelectedObjs = aPanel->getSelectedGeomObjects(); + QMap aSelectedObjsMap; + foreach( QString aName, aSelectedObjs ) + aSelectedObjsMap[aName] = true; + + // Select the appropriate geometry object shape in the viewer selectionMgr()->clearSelected(); // Unhighlight all objects except selected - HYDROGUI_Shape* aShape; - HYDROGUI_Shape* aSelectedShape = 0; + HYDROGUI_Shape* aShape = 0, *aLastShape = 0; Handle(HYDROData_Entity) anEntity; HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects(); HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); @@ -283,27 +291,15 @@ void HYDROGUI_CalculationOp::onObjectSelected ( const QString & theObjName ) if ( aShape ) { aName = anEntity->GetName(); - isSelected = ( aName == theObjName ); - if ( isSelected ) - { - aSelectedShape = aShape; - } - if ( aShape->isHighlighted() != isSelected ) - { - if ( !isSelected ) - { - aShape->highlight( isSelected ); - aShape->update(); - } - } + isSelected = aSelectedObjsMap.contains( aName ); + aShape->highlight( isSelected, false ); + aShape->update( false ); + aLastShape = aShape; } } } - if ( aSelectedShape ) - { - aSelectedShape->highlight( true ); - aSelectedShape->update(); - } + if( aLastShape ) + aLastShape->update( true ); } void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem ) @@ -553,43 +549,50 @@ void HYDROGUI_CalculationOp::onApply() } } -void HYDROGUI_CalculationOp::onSplitZones() +void HYDROGUI_CalculationOp::onNext( const int theIndex ) { - HYDROGUI_CalculationDlg* aPanel = - ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return; - - QApplication::setOverrideCursor( Qt::WaitCursor ); - - QString aNewCaseName = aPanel->getObjectName(); - QString anOldCaseName = myEditedObject->GetName(); + if( theIndex==1 ) + { + setAvailableGroups(); + } + else if( theIndex==2 ) + { + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; - bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName; + QApplication::setOverrideCursor( Qt::WaitCursor ); - // At first we must to update the case name because of - // automatic names generation for regions and zones - myEditedObject->SetName( aNewCaseName ); + QString aNewCaseName = aPanel->getObjectName(); + QString anOldCaseName = myEditedObject->GetName(); - if ( myEditedObject->IsMustBeUpdated() ) - { - myShowZones = true; - myEditedObject->Update(); + bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName; + + // At first we must to update the case name because of + // automatic names generation for regions and zones + myEditedObject->SetName( aNewCaseName ); + + if ( myEditedObject->IsMustBeUpdated() ) + { + myShowZones = true; + myEditedObject->Update(); - //aPanel->setEditedObject( myEditedObject ); - aPanel->refreshZonesBrowser(); + //aPanel->setEditedObject( myEditedObject ); + aPanel->refreshZonesBrowser(); - createPreview(); - } - else - { - setZonesVisible( true ); - } + createPreview(); + } + else + { + setZonesVisible( true ); + } - if ( anIsToUpdateOb ) - module()->getApp()->updateObjectBrowser( false ); + if ( anIsToUpdateOb ) + module()->getApp()->updateObjectBrowser( false ); - QApplication::restoreOverrideCursor(); + QApplication::restoreOverrideCursor(); + } } void HYDROGUI_CalculationOp::onHideZones() @@ -768,4 +771,15 @@ void HYDROGUI_CalculationOp::closePreview() } } +void HYDROGUI_CalculationOp::setAvailableGroups() +{ + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects(); + for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ ) + { + Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) ); + //TODO: anObj->GetGroups(); + } +} diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.h b/src/HYDROGUI/HYDROGUI_CalculationOp.h index 1ede7ff6..d60637c5 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.h +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.h @@ -54,6 +54,8 @@ protected: virtual void onApply(); virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); + void setAvailableGroups(); + protected slots: /** * Add geometry objects selected in the module browser to the calculation case. @@ -79,7 +81,7 @@ protected slots: /** * Case objects must be splitted to zones if the case has been modified or new. */ - void onSplitZones(); + void onNext( const int ); void onLastViewClosed( SUIT_ViewManager* ); /** * The zone is selected in the browser on the second page of the wizard. @@ -92,7 +94,7 @@ protected slots: /** * Geometry object is selected in the list on the first wizard page */ - void onObjectSelected ( const QString & theObjName ); + void onObjectsSelected(); /** * Boundary polyline is selected in the list on the first wizard page */ diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 8ff001e2..ceafe1eb 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -377,7 +377,7 @@ void HYDROGUI_Shape::setVisible( const bool theState, myContext->Erase( myShape, theIsUpdateViewer ); } -void HYDROGUI_Shape::highlight( bool theIsHighlight ) +void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer ) { if ( myIsHighlight == theIsHighlight ) return; @@ -388,7 +388,7 @@ void HYDROGUI_Shape::highlight( bool theIsHighlight ) return; colorShapeBorder( getActiveColor() ); - myContext->Display( myShape ); + myContext->Display( myShape, isUpdateViewer ); } bool HYDROGUI_Shape::isHighlighted() const diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 31966461..a1af4dbb 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -46,7 +46,7 @@ public: virtual void display( const bool theIsUpdateViewer = true ); virtual void erase( const bool theIsUpdateViewer = true ); - virtual void highlight( bool theIsHighlight ); + virtual void highlight( bool theIsHighlight, bool isUpdateViewer ); virtual bool isHighlighted() const; Handle(HYDROData_Entity) getObject() const { return myObject; } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 7267eefb..08ae62f6 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -201,6 +201,14 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) INCLUDED_OBJECTS Included objects + + AVAILABLE_GROUPS + Available groups + + + INCLUDED_GROUPS + Included groups + LIMITS Limits -- 2.39.2