From 1fa9edc1fcd05b4a5e87715ada0276431cf5aad2 Mon Sep 17 00:00:00 2001 From: mkr Date: Fri, 23 Oct 2015 16:07:39 +0300 Subject: [PATCH] refs #665 - #669: remove, split and merge operations are added. --- src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx | 17 ++++ src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h | 5 ++ src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx | 99 ++++++++++++++++++--- src/HYDROGUI/HYDROGUI_LandCoverMapOp.h | 3 +- src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h | 3 +- src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx | 12 ++- src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h | 4 +- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 12 +++ 8 files changed, 133 insertions(+), 22 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx index 0c964637..9c57ed86 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.cxx @@ -74,9 +74,12 @@ HYDROGUI_LandCoverMapDlg::HYDROGUI_LandCoverMapDlg( HYDROGUI_Module* theModule, addStretch(); + // Connect signals and slots + connect( myObjectNameEdit, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onLandCoverMapChanged() ) ); connect( myPolylinesFaces, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onPolylineFaceChanged( const QString& ) ) ); updateState( true ); + } HYDROGUI_LandCoverMapDlg::~HYDROGUI_LandCoverMapDlg() @@ -153,6 +156,16 @@ bool HYDROGUI_LandCoverMapDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) myOperationId == SplitLandCoverId ) ) ); } +void HYDROGUI_LandCoverMapDlg::onLandCoverMapChanged() +{ + if ( signalsBlocked() ) + return; + + reset(); + + emit landCoverMapChanged( getObjectName() ); +} + void HYDROGUI_LandCoverMapDlg::onPolylineFaceChanged( const QString& ) { updateState(); @@ -189,5 +202,9 @@ 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_LandCoverMapDlg.h b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h index 211740c8..d611b171 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapDlg.h @@ -54,7 +54,12 @@ public: virtual bool isOk( const Handle(HYDROData_Entity)& ) const; +signals: + void landCoverMapChanged( const QString& theName ); + void CreatePreview( const QStringList& thePolylineFaceNames ); + private slots: + void onLandCoverMapChanged(); void onPolylineFaceChanged( const QString& ); private: diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index 96655be1..3de085b9 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -31,6 +31,10 @@ #include #include +#include +#include +#include + HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, const int theOperationId ) : HYDROGUI_Operation( theModule ), myOperationId( theOperationId ), @@ -120,9 +124,11 @@ void HYDROGUI_LandCoverMapOp::commitOperation() HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const { HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId ); - /* + connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ), + 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() ) ); */ @@ -156,9 +162,12 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, } } - // Get selected polyline/face Handle(HYDROData_PolylineXY) aPolyline; Handle(HYDROData_Object) aFace; + + TopTools_ListOfShape aFacesSelectedInViewer; + + // Get polyline/face selected in combo-box if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == SplitLandCoverId ) { Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace(); @@ -170,6 +179,12 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, return false; } } + // Get face(s) selected in the 3d viewer + else if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId ) + { + // TODO: + //Fill in aFacesSelectedInViewer list + } // Get selected Strickler type QString aSelectedStricklerType; @@ -190,6 +205,7 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, // Set land cover map name aLandCoverMapObj->SetName( anObjectName ); + // Add land cover to new / edited land cover map if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId ) { bool aLandCoverAdded = false; @@ -203,30 +219,69 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, return false; } } - - /*TCollection_AsciiString anError; - if ( HYDROData_LandCover::buildShape( aZonePolylines, anError ).IsNull() ) + + // Remove land cover from edited land cover map + if ( myOperationId == RemoveLandCoverId ) + { + bool aLandCoverRemoved = false; + if ( !aFacesSelectedInViewer.IsEmpty() ) + { + aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer ); + if ( !aLandCoverRemoved ) + { + theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" ); + return false; + } + } + } + + // Split land cover(s) inside edited land cover map + if ( myOperationId == SplitLandCoverId ) { - if ( !anError.IsEmpty() ) { - theErrorMsg = HYDROGUI_Tool::ToQString( anError ); - } else { - theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" ); + bool aLandCoverSplitted = false; + if ( !aPolyline.IsNull() ) + aLandCoverSplitted = aLandCoverMapObj->Split( aPolyline ); + else if ( !aFace.IsNull() ) + { + // TODO: + //Get the complete boundary of the object face as the splitting polyline + Handle(HYDROData_PolylineXY) aBoundaryPolyline; + aLandCoverSplitted = aLandCoverMapObj->Split( aBoundaryPolyline ); } - return false; - }*/ + if ( !aLandCoverSplitted ) + { + theErrorMsg = tr( "LAND_COVER_NOT_SPLITTED" ); + return false; + } + } + // Merge land covers inside edited land cover map + if ( myOperationId == MergeLandCoverId ) + { + bool aLandCoverMerged = false; + if ( !aFacesSelectedInViewer.IsEmpty() ) + { + aLandCoverMerged = aLandCoverMapObj->Merge( aFacesSelectedInViewer, aSelectedStricklerType ); + if ( !aLandCoverMerged ) + { + theErrorMsg = tr( "LAND_COVER_NOT_MERGED" ); + return false; + } + } + } + /*if ( myOperationId == CreateLandCoverMapId ) { aLandCoverMapObj->SetFillingColor( aLandCoverMapObj->DefaultFillingColor() ); aLandCoverMapObj->SetBorderColor( aLandCoverMapObj->DefaultBorderColor() ); }*/ - //aLandCoverMapObj->SetPolylines( aZonePolylines ); - //aLandCoverMapObj->SetStricklerType( aSelectedStricklerType ); + // Update land cover map object and close preview aLandCoverMapObj->Update(); closePreview(); + // Publish the newly created land cover map in the Object Browser module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true ); if ( myOperationId == CreateLandCoverMapId ) { @@ -234,6 +289,7 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, theBrowseObjectsEntries.append( anEntry ); } + // Update presentation of land cover object in the 3d viewer module()->setIsToUpdate( aLandCoverMapObj ); module()->getOCCDisplayer()->SetToUpdateColorScale(); @@ -242,7 +298,22 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, return true; } -void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineNames ) +void HYDROGUI_LandCoverMapOp::onLandCoverMapChanged( const QString& theName ) +{ + // If the edited land cover map was changed in the combo-box, update myEditedObject + if ( myOperationId != CreateLandCoverMapId ) + { + myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName ) ); + if ( !myEditedObject.IsNull() ) + { + // Show preview of the newly selected land cover map + QStringList aPolylineFaceNames; + onCreatePreview( aPolylineFaceNames ); + } + } +} + +void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineFaceNames ) { /* HYDROGUI_LandCoverDlg* aPanel = ::qobject_cast( inputPanel() ); diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h index 092af90e..cdbed36e 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.h @@ -44,7 +44,8 @@ protected: virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; protected slots: - void onCreatePreview( const QStringList& thePolylineNames ); + void onLandCoverMapChanged( const QString& theName ); + void onCreatePreview( const QStringList& thePolylineFaceNames ); private: void closePreview(); diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h index e1acc832..dabe4526 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapPrs.h @@ -52,8 +52,9 @@ public: Quantity_Color GetColor( const QString& theStricklerType ) const; -protected: void UpdateColors(); + +protected: void SetHilightAttributes( const Quantity_Color& theEdgesColor ); private: diff --git a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx index fddf6e70..c365cfc4 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.cxx @@ -51,16 +51,20 @@ void HYDROGUI_ShapeLandCoverMap::update( bool theIsUpdateViewer, bool isDeactiva setShape( aLandCoverMapShape, false, false ); } + /* TODO if ( !myIsScalarMapMode ) { - // TODO - QColor aFillingColor = Qt::gray;//aLandCoverMapObj->GetFillingColor(); - QColor aBorderColor = Qt::black;//aLandCoverMapObj->GetBorderColor(); + QColor aFillingColor = aLandCoverMapObj->GetFillingColor(); + QColor aBorderColor = aLandCoverMapObj->GetBorderColor(); setFillingColor( aFillingColor, false, false ); setBorderColor( aBorderColor, false, false ); } else { updateShape( false, false ); - } + }*/ + + Handle(HYDROGUI_LandCoverMapPrs) aLandCoverMapPrs = Handle(HYDROGUI_LandCoverMapPrs)::DownCast( getAISObject() ); + if ( !aLandCoverMapPrs.IsNull() ) + aLandCoverMapPrs->UpdateColors(); HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection ); } diff --git a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h index 025a0fcc..9fdc6e83 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h +++ b/src/HYDROGUI/HYDROGUI_ShapeLandCoverMap.h @@ -56,8 +56,8 @@ protected: virtual Handle_AIS_InteractiveObject createShape() const; private: - HYDROGUI_OCCDisplayer* myDisplayer; - bool myIsScalarMapMode; + HYDROGUI_OCCDisplayer* myDisplayer; + bool myIsScalarMapMode; }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 7b62597c..95c6c91e 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2799,6 +2799,18 @@ Polyline should consist from one not closed curve. LAND_COVER_NOT_ADDED Land cover can not be added. + + LAND_COVER_NOT_REMOVED + Land cover can not be removed. + + + LAND_COVER_NOT_SPLITTED + Land cover can not be splitted. + + + LAND_COVER_NOT_MERGED + Land cover can not be merged. + LAND_COVER_OBJECT_CANNOT_BE_CREATED Land Cover object can not be created -- 2.39.2