From 6b115ad6b192941292b8d7cae8de9b632b771a46 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 11 Nov 2015 20:59:05 +0300 Subject: [PATCH] refs #668, #669: finalize implementation of split and merge land cover(s) operations. --- src/HYDROData/HYDROData_LandCoverMap.cxx | 5 +- src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx | 129 +++++++++++++++-------- src/HYDROGUI/HYDROGUI_LandCoverMapOp.h | 25 +++-- src/HYDROGUI/HYDROGUI_Shape.cxx | 43 +++++++- src/HYDROGUI/HYDROGUI_Shape.h | 4 + 5 files changed, 149 insertions(+), 57 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 07251838..bc0f1551 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -509,6 +509,9 @@ bool HYDROData_LandCoverMap::Remove( const TopTools_ListOfShape& theFacesToRemov if( !aFacesToRemove.Contains( anIt.Face() ) ) aNewFaces.Add( anIt.Face(), anIt.StricklerType() ); + if ( aNewFaces.IsEmpty() ) + return false; + StoreLandCovers( aNewFaces ); return true; } @@ -549,7 +552,7 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const { // 1. to fuse the faces into the new face TopoDS_Shape aMergedFace = MergeFaces( theFaces, true ); - if( aMergedFace.ShapeType()==TopAbs_FACE ) + if( !aMergedFace.IsNull() && aMergedFace.ShapeType()==TopAbs_FACE ) { // 2. to remove the merged faces from the current map Remove( theFaces ); diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index 5a4acc55..a498b867 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -25,15 +25,24 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_DataObject.h" +#include "HYDROGUI_ShapeLandCoverMap.h" #include #include #include #include +#include +#include + +#include + #include #include #include +#include + +#include HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId ) : HYDROGUI_Operation( theModule ), @@ -106,8 +115,14 @@ void HYDROGUI_LandCoverMapOp::startOperation() } } aPanel->setObjectName( anObjectName ); - + + closePreview(); + QStringList aPolylineFaceNames; + onCreatePreview( aPolylineFaceNames ); + aPanel->blockSignals( false ); + + module()->update( UF_OCCViewer | UF_FitAll ); } void HYDROGUI_LandCoverMapOp::abortOperation() @@ -115,6 +130,8 @@ void HYDROGUI_LandCoverMapOp::abortOperation() closePreview(); HYDROGUI_Operation::abortOperation(); + + module()->update( UF_OCCViewer | UF_FitAll ); } void HYDROGUI_LandCoverMapOp::commitOperation() @@ -122,6 +139,8 @@ void HYDROGUI_LandCoverMapOp::commitOperation() closePreview(); HYDROGUI_Operation::commitOperation(); + + module()->update( UF_OCCViewer | UF_FitAll ); } HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const @@ -131,10 +150,6 @@ HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const this, SLOT( onLandCoverMapChanged( const QString& ) ) ); connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ), this, SLOT( onCreatePreview( const QStringList& ) ) ); - /* - connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) ); - connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) ); - */ return aPanel; } @@ -187,8 +202,22 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) { - // TODO: - //Fill in aFacesSelectedInViewer list + 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 ); + } + } + } } // Get selected Strickler type @@ -287,12 +316,6 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, } } - /*if ( myOperationId == CreateLandCoverMapId ) - { - aLandCoverMapObj->SetFillingColor( aLandCoverMapObj->DefaultFillingColor() ); - aLandCoverMapObj->SetBorderColor( aLandCoverMapObj->DefaultBorderColor() ); - }*/ - // Update land cover map object and close preview aLandCoverMapObj->Update(); @@ -324,6 +347,7 @@ void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName ) if ( !myEditedObject.IsNull() ) { // Show preview of the newly selected land cover map + closePreview(); QStringList aPolylineFaceNames; onCreatePreview( aPolylineFaceNames ); } @@ -332,27 +356,12 @@ void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName ) void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFaceNames ) { - /* - HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) return; QApplication::setOverrideCursor( Qt::WaitCursor ); - HYDROData_SequenceOfObjects aZonePolylines; - QStringList::const_iterator anIt = thePolylineNames.begin(), aLast = thePolylineNames.end(); - for( ; anIt!=aLast; anIt++ ) - { - QString aPolylineName = *anIt; - Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) ); - if ( !aPolyline.IsNull() ) - aZonePolylines.Append( aPolyline ); - } - - TCollection_AsciiString anError; - TopoDS_Shape aZoneShape = HYDROData_LandCover::buildShape( aZonePolylines, anError ); - LightApp_Application* anApp = module()->getApp(); if ( !getPreviewManager() ) setPreviewManager( ::qobject_cast( @@ -364,28 +373,45 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFac { Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); if ( !aCtx.IsNull() ) - myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + { + connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); + myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ ); + } } } if ( aViewManager && myPreviewPrs ) { - QColor aFillingColor = Qt::magenta; - QColor aBorderColor = Qt::transparent; - if ( !myEditedObject.IsNull() ) { - aFillingColor = myEditedObject->GetFillingColor(); - aBorderColor = myEditedObject->GetBorderColor(); + TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape(); + if( !aLandCoverMapShape.IsNull() ) + { + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId) + myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); + myPreviewPrs->setShape( aLandCoverMapShape ); } + } + + module()->update( UF_OCCViewer | UF_FitAll ); - myPreviewPrs->setFillingColor( aFillingColor, false, false ); - myPreviewPrs->setBorderColor( aBorderColor, false, false ); + QApplication::restoreOverrideCursor(); +} - if( !aZoneShape.IsNull() ) - myPreviewPrs->setShape( aZoneShape ); - } +void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged() +{ + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; - QApplication::restoreOverrideCursor(); - */ + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( !aCtx.IsNull() ) + { + int aNbSelected = aCtx->NbSelected(); + + if ( myOperationId == RemoveLandCoverId ) + aPanel->setApplyEnabled( aNbSelected > 0 ); + else if ( myOperationId == MergeLandCoverId ) + aPanel->setApplyEnabled( aNbSelected > 1 ); + } } void HYDROGUI_LandCoverMapOp::closePreview() @@ -395,4 +421,23 @@ void HYDROGUI_LandCoverMapOp::closePreview() delete myPreviewPrs; myPreviewPrs = 0; } + + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId ) + aPanel->setApplyEnabled( false ); +} + +Handle(AIS_InteractiveContext) HYDROGUI_LandCoverMapOp::getInteractiveContext() +{ + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + Handle(AIS_InteractiveContext) aCtx = NULL; + if ( aViewManager ) { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) { + aCtx = aViewer->getAISContext(); + } + } + return aCtx; } diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h index cdbed36e..f73126af 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h @@ -23,6 +23,8 @@ #include +#include + class HYDROGUI_LandCoverMapOp : public HYDROGUI_Operation { Q_OBJECT @@ -32,23 +34,26 @@ public: virtual ~HYDROGUI_LandCoverMapOp(); protected: - virtual void startOperation(); - virtual void abortOperation(); - virtual void commitOperation(); + virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); - virtual HYDROGUI_InputPanel* createInputPanel() const; + virtual HYDROGUI_InputPanel* createInputPanel() const; - virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, - QStringList& theBrowseObjectsEntries ); + virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, + QStringList& theBrowseObjectsEntries ); - virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; + virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; protected slots: - void onLandCoverMapChanged( const QString& theName ); - void onCreatePreview( const QStringList& thePolylineFaceNames ); + void onLandCoverMapChanged( const QString& theName ); + void onCreatePreview( const QStringList& thePolylineFaceNames ); + void onViewerSelectionChanged(); private: - void closePreview(); + void closePreview(); + + Handle(AIS_InteractiveContext) getInteractiveContext(); private: int myOperationId; diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index f7132b32..5fb6e381 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -55,7 +55,8 @@ HYDROGUI_Shape::HYDROGUI_Shape( const Handle(AIS_InteractiveContext)& theContext myHighlightColor( Qt::white ), myIsToUpdate( false ), myIsVisible( true ), - myDisplayMode( AIS_Shaded ) + myDisplayMode( AIS_Shaded ), + mySelectionMode( AIS_Shape::SelectionMode( TopAbs_SHAPE ) ) { } @@ -115,7 +116,7 @@ void HYDROGUI_Shape::erase( const bool theIsUpdateViewer ) if ( myContext.IsNull() || myShape.IsNull() ) return; - myContext->Erase( myShape, theIsUpdateViewer ); + eraseShape( theIsUpdateViewer ); } void HYDROGUI_Shape::update( bool isUpdateViewer, @@ -326,7 +327,7 @@ void HYDROGUI_Shape::setVisible( const bool theState, displayShape( theIsUpdateViewer ); } else - myContext->Erase( myShape, theIsUpdateViewer ); + eraseShape( theIsUpdateViewer ); } void HYDROGUI_Shape::highlight( bool theIsHighlight, bool isUpdateViewer ) @@ -517,6 +518,7 @@ void HYDROGUI_Shape::buildShape() myShape->SetTransparency( 0 ); myShape->SetDisplayMode( (AIS_DisplayMode)myDisplayMode ); + myShape->SetSelectionMode( (Standard_Integer)mySelectionMode ); // Init default params for shape const Handle(Prs3d_Drawer)& anAttributes = myShape->Attributes(); @@ -594,7 +596,27 @@ void HYDROGUI_Shape::updateShape( const bool theToDisplay, void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer ) { - myContext->Display( myShape, Standard_False ); + if ( myContext->HasOpenedContext() && mySelectionMode > 0 ) + myContext->CloseLocalContext(); + + if ( mySelectionMode > 0 ) + // Display object in local context with selection + myContext->Display( myShape, myDisplayMode, mySelectionMode, Standard_False, Standard_False ); + else + { + if ( !myContext->HasOpenedContext() ) + // Ordinary display of object published in the Object Browser + myContext->Display( myShape, Standard_False ); + else + // Display object in local context without selection + myContext->Display( myShape, myDisplayMode, -1, Standard_False, Standard_False ); + } + + if ( mySelectionMode > 0 ) + { + myContext->OpenLocalContext(); + myContext->Activate( myShape, mySelectionMode, Standard_True ); + } if ( myZLayer >= 0 ) myContext->SetZLayer( myShape, myZLayer ); @@ -604,6 +626,14 @@ void HYDROGUI_Shape::displayShape( const bool theIsUpdateViewer ) } } +void HYDROGUI_Shape::eraseShape( const bool theIsUpdateViewer ) +{ + if ( myContext->HasOpenedContext() && mySelectionMode > 0 ) + myContext->CloseLocalContext(); + + myContext->Erase( myShape, theIsUpdateViewer ); +} + QColor HYDROGUI_Shape::getActiveColor() const { return isHighlighted() ? myHighlightColor : myBorderColor; @@ -669,3 +699,8 @@ void HYDROGUI_Shape::setDisplayMode( int theDisplayMode ) { myDisplayMode = theDisplayMode; } + +void HYDROGUI_Shape::setSelectionMode( int theSelectionMode ) +{ + mySelectionMode = theSelectionMode; +} \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index 0acd1a45..69531058 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -98,11 +98,14 @@ public: void setZLayer( const int theZLayer ); + void setSelectionMode( int theSelectionMode ); + protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, const bool theIsUpdateViewer = true ); virtual void displayShape( const bool theIsUpdateViewer ); + virtual void eraseShape( const bool theIsUpdateViewer ); virtual QColor getActiveColor() const; virtual Handle_AIS_InteractiveObject createShape() const; @@ -126,6 +129,7 @@ private: bool myIsHighlight; TopoDS_Shape myTopoShape; int myDisplayMode; + int mySelectionMode; QColor myFillingColor; QColor myBorderColor; -- 2.39.2