From: mkr Date: Thu, 12 Nov 2015 09:03:53 +0000 (+0300) Subject: refs #669, #671: implementation of change land cover type operation, set default... X-Git-Tag: v1.5~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d4bb018666a815232d1dbd84c90dfa30b995168b;p=modules%2Fhydro.git refs #669, #671: implementation of change land cover type operation, set default Strickler type from the first selected land cover for merge and change type operations. --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index bc0f1551..d33d90de 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -646,6 +646,37 @@ TopoDS_Shape HYDROData_LandCoverMap::MergeFaces( const TopTools_ListOfShape& the return aResult; } +/** + Change Strickler type for the list of faces to the given one + @param theFaces the faces to change type + @param theType the Strickler type for the given land cover(s) + @return if the change type operation is successful +*/ +bool HYDROData_LandCoverMap::ChangeType( const TopTools_ListOfShape& theFaces, const QString& theType ) +{ + HYDROData_MapOfFaceToStricklerType aFacesToChangeType; + TopTools_ListIteratorOfListOfShape aFIt( theFaces ); + for( ; aFIt.More(); aFIt.Next() ) + { + TopoDS_Shape aShape = aFIt.Value(); + if( aShape.ShapeType()==TopAbs_FACE ) + aFacesToChangeType.Add( TopoDS::Face( aShape ), "" ); + } + + int aNbChanges = 0; + Iterator anIt( *this ); + for( ; anIt.More(); anIt.Next() ) + if( aFacesToChangeType.Contains( anIt.Face() ) ) + { + anIt.SetStricklerType( theType ); + aNbChanges++; + } + if ( aNbChanges != theFaces.Extent() ) + return false; + + return true; +} + /** Get the shape of the land cover map */ @@ -654,6 +685,26 @@ TopoDS_Shape HYDROData_LandCoverMap::GetShape() const return HYDROData_Entity::GetShape( DataTag_Shape ); } +/** + Get Strickler type of the given land cover + @param theLandCover the land cover to get Strickler type of + @return name of Strickler type +*/ +QString HYDROData_LandCoverMap::StricklerType( const TopoDS_Face& theLandCover ) const +{ + QString aType = ""; + + Iterator anIt( *this ); + for( ; anIt.More(); anIt.Next() ) + if( anIt.Face().IsEqual( theLandCover) ) + { + aType = anIt.StricklerType(); + break; + } + + return aType; +} + /** Set the shape of the land cover map @param theShape the new shape for the land cover map diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 9ab0276c..9ce1613e 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -109,10 +109,14 @@ public: HYDRODATA_EXPORT bool Split( const TopoDS_Shape& ); HYDRODATA_EXPORT bool Merge( const TopTools_ListOfShape&, const QString& theType ); + HYDRODATA_EXPORT bool ChangeType( const TopTools_ListOfShape&, const QString& theType ); + HYDRODATA_EXPORT TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const; HYDRODATA_EXPORT TopoDS_Shape GetShape() const; + HYDRODATA_EXPORT QString StricklerType( const TopoDS_Face& ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; HYDRODATA_EXPORT int GetLCCount() const; diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx index ec2a3e5c..57bcaff7 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx @@ -203,9 +203,5 @@ void HYDROGUI_LandCoverMapDlg::updateState( bool theInitialConfigure ) anEmptyPolylineFaceName = getPolylineFaceName().isEmpty(); setApplyEnabled( !anEmptyObjectName && !anEmptyPolylineFaceName ); - - // TODO: - //if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId ) => enable Apply, - //Apply and Close buttons only if at least one face (land cover) is selected in the 3d viewer } } diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index a498b867..2ec102f4 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -37,6 +37,7 @@ #include +#include #include #include #include @@ -205,18 +206,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, if ( myPreviewPrs ) { // Fill in aFacesSelectedInViewer list - Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); - if ( !aCtx.IsNull() && aCtx->NbSelected() > 0 ) - { - for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() ) - { - TopoDS_Shape aSelectedShape = aCtx->SelectedShape(); - if ( aSelectedShape.IsNull() ) - continue; - - aFacesSelectedInViewer.Append( aSelectedShape ); - } - } + Handle(AIS_InteractiveContext) aCtx; + getSelectedShapes( aFacesSelectedInViewer, aCtx ); } } @@ -224,7 +215,8 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, QString aSelectedStricklerType; if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || - myOperationId == MergeLandCoverId ) + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) { aSelectedStricklerType = aPanel->getSelectedStricklerTypeName(); if ( aSelectedStricklerType.isEmpty() ) @@ -315,6 +307,21 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, } } } + + // Change Strickler type for land cover(s) inside edited land cover map + if ( myOperationId == ChangeLandCoverTypeId ) + { + bool aLandCoverChangeType = false; + if ( !aFacesSelectedInViewer.IsEmpty() ) + { + aLandCoverChangeType = aLandCoverMapObj->ChangeType( aFacesSelectedInViewer, aSelectedStricklerType ); + if ( !aLandCoverChangeType ) + { + theErrorMsg = tr( "LAND_COVER_TYPE_NOT_CHANGED" ); + return false; + } + } + } // Update land cover map object and close preview aLandCoverMapObj->Update(); @@ -385,7 +392,9 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFac TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape(); if( !aLandCoverMapShape.IsNull() ) { - if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId) + if ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); myPreviewPrs->setShape( aLandCoverMapShape ); } @@ -407,10 +416,27 @@ void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged() { int aNbSelected = aCtx->NbSelected(); - if ( myOperationId == RemoveLandCoverId ) + 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 ( aNbSelected == 1 && !myEditedObject.IsNull() ) + { + TopTools_ListOfShape aFacesSelectedInViewer; + getSelectedShapes( aFacesSelectedInViewer, aCtx ); + if ( aFacesSelectedInViewer.Extent() == 1 ) + { + QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) ); + if ( !aType.isEmpty() ) + aPanel->setSelectedStricklerTypeName( aType ); + } + } + } } } @@ -426,7 +452,7 @@ void HYDROGUI_LandCoverMapOp::closePreview() if ( !aPanel ) return; - if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId ) + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) aPanel->setApplyEnabled( false ); } @@ -441,3 +467,22 @@ Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext() } return aCtx; } + +void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes, + Handle(AIS_InteractiveContext)& theCtx ) +{ + if ( theCtx.IsNull() ) + theCtx = getInteractiveContext(); + + if ( !theCtx.IsNull() && theCtx->NbSelected() > 0 ) + { + for ( theCtx->InitSelected(); theCtx->MoreSelected(); theCtx->NextSelected() ) + { + TopoDS_Shape aSelectedShape = theCtx->SelectedShape(); + if ( aSelectedShape.IsNull() ) + continue; + + theSelectedShapes.Append( aSelectedShape ); + } + } +} diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h index f73126af..55cc12df 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h @@ -54,6 +54,8 @@ private: void closePreview(); Handle(AIS_InteractiveContext) getInteractiveContext(); + void getSelectedShapes( TopTools_ListOfShape& theSelectedShapes, + Handle(AIS_InteractiveContext)& theCtx ); private: int myOperationId; diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index f8baa64d..05e583ab 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -678,6 +678,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); theMenu->addAction( action( SplitLandCoverId ) ); theMenu->addAction( action( MergeLandCoverId ) ); + theMenu->addAction( action( ChangeLandCoverTypeId ) ); theMenu->addSeparator(); // theMenu->addAction( action( ExportToShapeFileID ) ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 84804add..b88069db 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -569,8 +569,6 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case RemoveLandCoverId: case SplitLandCoverId: case MergeLandCoverId: - anOp = new HYDROGUI_LandCoverMapOp( aModule, theId ); - break; case ChangeLandCoverTypeId: anOp = new HYDROGUI_LandCoverMapOp( aModule, theId ); break; diff --git a/src/HYDROGUI/resources/HYDROGUI_images.ts b/src/HYDROGUI/resources/HYDROGUI_images.ts index cec1aa6e..207f7779 100644 --- a/src/HYDROGUI/resources/HYDROGUI_images.ts +++ b/src/HYDROGUI/resources/HYDROGUI_images.ts @@ -398,6 +398,10 @@ MERGE_LAND_COVER_ICO icon_merge_land_cover.png + + CHANGE_LAND_COVER_TYPE_ICO + icon_change_land_cover_type.png + IMPORT_OBSTACLE_FROM_FILE_ICO diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 756d258c..1c10d4f4 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -876,6 +876,10 @@ Would you like to remove all references from the image? DSK_MERGE_LAND_COVER Merge land covers + + DSK_CHANGE_LAND_COVER_TYPE + Change land cover(s) type + DSK_COPY Copy @@ -1177,6 +1181,10 @@ Would you like to remove all references from the image? MEN_MERGE_LAND_COVER Merge land covers + + MEN_CHANGE_LAND_COVER_TYPE + Change land cover(s) type + MEN_CUT_IMAGES Cut images @@ -1514,6 +1522,10 @@ Would you like to remove all references from the image? STB_MERGE_LAND_COVER Merge land covers + + STB_CHANGE_LAND_COVER_TYPE + Change land cover(s) type + STB_COPY Copy @@ -2880,6 +2892,10 @@ Polyline should consist from one not closed curve. MERGE_LAND_COVER Merge land covers inside the land cover map + + CHANGE_LAND_COVER_TYPE + Change Strickler type(s) assigned to the land cover(s) inside the land cover map + POLYLINE_FACE_NOT_DEFINED Polyline / Face object should be defined. @@ -2904,6 +2920,10 @@ Polyline should consist from one not closed curve. LAND_COVER_NOT_MERGED Land cover can not be merged. + + LAND_COVER_TYPE_NOT_CHANGED + Strickler type can not be changed for all selected land covers. + LAND_COVER_OBJECT_CANNOT_BE_CREATED Land Cover object can not be created