From 111dbd368f89de43e3f6f555ecfc254f6ec3ca3a Mon Sep 17 00:00:00 2001 From: mkr Date: Tue, 17 Nov 2015 15:49:11 +0300 Subject: [PATCH] refs #688, #689: bugs fixes. --- src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx | 22 ++++ src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h | 3 + src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx | 123 ++++++++++++++-------- src/HYDROGUI/HYDROGUI_LandCoverMapOp.h | 5 +- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 8 ++ 5 files changed, 118 insertions(+), 43 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx index 57bcaff7..be0bb55c 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx @@ -68,9 +68,15 @@ HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule, aParamLayout->addWidget( myStricklerTypesLabel, 1, 0, 1, 1 ); aParamLayout->addWidget( myStricklerTypes, 1, 1, 1, 1 ); + // Label indicated the number of selected land covers + QString aDefaultLabel( "0" ); + mySelectedLandCoversLabel = new QLabel( tr( "LAND_COVER_MAP_SELECTED_FACES" ) + aDefaultLabel, myParamGroup ); + mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : red; }"); + // Common addWidget( myObjectNameGroup ); addWidget( myParamGroup ); + addWidget( mySelectedLandCoversLabel ); addStretch(); @@ -147,6 +153,17 @@ QString HYDROGUI_LandCoverMapDlg::getSelectedStricklerTypeName() const return myStricklerTypes->getSelectedStricklerTypeName(); } +void HYDROGUI_LandCoverMapDlg::updateSelectedLandCoversLabel( int theNbSelected ) +{ + QString aLabel; + aLabel.setNum( theNbSelected ); + if ( theNbSelected == 0 ) + mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : red; }"); + else + mySelectedLandCoversLabel->setStyleSheet("QLabel { font: italic; color : black; }"); + mySelectedLandCoversLabel->setText( tr( "LAND_COVER_MAP_SELECTED_FACES" ) + aLabel ); +} + bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const { Handle(HYDROData_PolylineXY) aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast(theEntity); @@ -193,6 +210,11 @@ void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure ) myOperationId == ChangeLandCoverTypeId ); myStricklerTypesLabel->setVisible( aShowStricklerTypesCtrls ); myStricklerTypes->setVisible( aShowStricklerTypesCtrls ); + + bool aShowSelectedLandCoversLabel = ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ); + mySelectedLandCoversLabel->setVisible( aShowSelectedLandCoversLabel ); } else { diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h index 62fd5601..2334a61a 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h @@ -52,6 +52,8 @@ public: void setSelectedStricklerTypeName( const QString& theName ); QString getSelectedStricklerTypeName() const; + void updateSelectedLandCoversLabel( int theNbSelected ); + virtual bool isOk( const Handle(HYDROData_Entity)& ) const; signals: @@ -75,6 +77,7 @@ private: HYDROGUI_ObjComboBox* myPolylinesFaces; QLabel* myStricklerTypesLabel; HYDROGUI_StricklerTypeComboBox* myStricklerTypes; + QLabel* mySelectedLandCoversLabel; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index 777ebf39..213256f6 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -221,11 +221,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, myOperationId == ChangeLandCoverTypeId ) { if ( myPreviewPrs ) - { // Fill in aFacesSelectedInViewer list - Handle(AIS_InteractiveContext) aCtx; - getSelectedShapes( aFacesSelectedInViewer, aCtx ); - } + getSelectedShapes( aFacesSelectedInViewer ); } // Get selected Strickler type @@ -440,15 +437,14 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview() if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() ) { - TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape(); - if( !aLandCoverMapShape.IsNull() ) - { - if ( myOperationId == RemoveLandCoverId || - myOperationId == MergeLandCoverId || - myOperationId == ChangeLandCoverTypeId ) - myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); - myPreviewPrs->setShape( aLandCoverMapShape ); - } + if ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) + myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); + myPreviewPrs->update( false, false ); + + if ( myOperationId == ChangeLandCoverTypeId ) + selectLandCoverInPreview(); } module()->update( UF_OCCViewer | UF_FitAll ); @@ -462,33 +458,32 @@ void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged() if ( !aPanel ) return; - Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); - if ( !aCtx.IsNull() ) - { - int aNbSelected = aCtx->NbSelected(); + int aNbSelected = getNbSelected(); - if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId ) - // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer - aPanel->setApplyEnabled( aNbSelected > 0 ); - else if ( myOperationId == MergeLandCoverId ) - // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer - aPanel->setApplyEnabled( aNbSelected > 1 ); + if ( myOperationId == RemoveLandCoverId || myOperationId == ChangeLandCoverTypeId ) + // Enable Apply, Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer + aPanel->setApplyEnabled( aNbSelected > 0 ); + else if ( myOperationId == MergeLandCoverId ) + // Enable Apply, Apply and Close buttons only if at least two faces (land covers) are selected in the 3d viewer + aPanel->setApplyEnabled( aNbSelected > 1 ); - if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + if ( myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + { + if ( aNbSelected == 1 && !myEditedObject.IsNull() ) { - if ( aNbSelected == 1 && !myEditedObject.IsNull() ) + TopTools_ListOfShape aFacesSelectedInViewer; + getSelectedShapes( aFacesSelectedInViewer ); + if ( aFacesSelectedInViewer.Extent() == 1 ) { - TopTools_ListOfShape aFacesSelectedInViewer; - getSelectedShapes( aFacesSelectedInViewer, aCtx ); - if ( aFacesSelectedInViewer.Extent() == 1 ) - { - QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) ); - if ( !aType.isEmpty() ) - aPanel->setSelectedStricklerTypeName( aType ); - } + QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) ); + if ( !aType.isEmpty() ) + aPanel->setSelectedStricklerTypeName( aType ); } } } + + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + aPanel->updateSelectedLandCoversLabel( aNbSelected ); } void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) @@ -616,17 +611,14 @@ Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext() return aCtx; } -void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes, - Handle(AIS_InteractiveContext)& theCtx ) +void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes ) { - if ( theCtx.IsNull() ) - theCtx = getInteractiveContext(); - - if ( !theCtx.IsNull() && theCtx->NbSelected() > 0 ) + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( !aCtx.IsNull() ) { - for ( theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected() ) + for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() ) { - TopoDS_Shape aSelectedShape = theCtx->SelectedShape(); + TopoDS_Shape aSelectedShape = aCtx->SelectedShape(); if ( aSelectedShape.IsNull() ) continue; @@ -634,3 +626,52 @@ void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelect } } } + +int HYDROGUI_LandCoverMapOp::getNbSelected() +{ + int aNbSelected = 0; + + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( !aCtx.IsNull() ) + { + for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() ) + { + TopoDS_Shape aSelectedShape = aCtx->SelectedShape(); + if ( aSelectedShape.IsNull() ) + continue; + aNbSelected++; + } + } + + return aNbSelected; +} + +void HYDROGUI_LandCoverMapOp::selectLandCoverInPreview() +{ + if ( myPreviewPrs && !myEditedObject.IsNull() && myEditedObject->GetLCCount() == 1 ) + { + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( !aViewManager ) + return; + + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( aCtx.IsNull() ) + return; + + OCCViewer_ViewWindow* aViewWindow = (OCCViewer_ViewWindow*)aViewManager->getActiveView(); + if ( !aViewWindow ) + return; + + OCCViewer_ViewPort3d* aViewPort = aViewWindow->getViewPort(); + if ( !aViewPort ) + return; + + Handle(V3d_View) aView = aViewPort->getView(); + if ( aView.IsNull() ) + return; + + aCtx->ShiftSelect( 0, 0, aViewPort->width(), aViewPort->height(), aView, Standard_False ); + aCtx->UpdateCurrentViewer(); + emit selectionChanged(); + } +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h index 0c08817e..d5c7e640 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h @@ -63,8 +63,9 @@ private: void closePreview(); Handle(AIS_InteractiveContext) getInteractiveContext(); - void getSelectedShapes( TopTools_ListOfShape& theSelectedShapes, - Handle(AIS_InteractiveContext)& theCtx ); + void getSelectedShapes( TopTools_ListOfShape& theSelectedShapes ); + int getNbSelected(); + void selectLandCoverInPreview(); private: int myOperationId; diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index cf5b2b4d..371a0199 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2900,6 +2900,14 @@ Polyline should consist from one not closed curve. LAND_COVER_MAP_STRICKLER_TYPE Strickler type + + LAND_COVER_MAP_SELECTED_FACES + + + This operation is performed on a set of land covers selected in the 3D Viewer. + + Number of selected land covers: + -- 2.39.2