X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_LandCoverMapOp.cxx;h=6426928ffcc0abd1874e10baef2245f8a37ce0a3;hb=5e509b7593f9d62024f6122ecba1322b697675e1;hp=96655be197d5f11dbf5b83091812536e003adea8;hpb=9c947f35615e69e9e54a8c4b074dd1f2be13689c;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index 96655be1..6426928f 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -22,19 +22,45 @@ #include "HYDROGUI_OCCDisplayer.h" #include "HYDROGUI_Operations.h" #include "HYDROGUI_LandCoverMapDlg.h" -#include "HYDROGUI_Tool.h" +#include "HYDROGUI_Tool2.h" #include "HYDROGUI_UpdateFlags.h" #include "HYDROGUI_DataObject.h" +#include "HYDROGUI_ShapeLandCoverMap.h" +#include "HYDROGUI_OCCSelector.h" #include #include #include #include +#include +#include +#include +#include + +#include + +#include +#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 ), myOperationId( theOperationId ), - myPreviewPrs( 0 ) + myPreviewPrs( 0 ), + myPolylineFacePreviewPrs( 0 ) { switch( myOperationId ) { @@ -53,6 +79,9 @@ HYDROGUI_LandCoverMapOp::HYDROGUI_LandCoverMapOp( HYDROGUI_Module* theModule, co case MergeLandCoverId: setName( tr( "MERGE_LAND_COVER" ) ); break; + case ChangeLandCoverTypeId: + setName( tr( "CHANGE_LAND_COVER_TYPE" ) ); + break; } } @@ -79,28 +108,47 @@ void HYDROGUI_LandCoverMapOp::startOperation() { if ( isApplyAndClose() ) myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - if ( !myEditedObject.IsNull() ) + + // Construct a list of names of all land cover map objects defined within the data model + QStringList aLandCoverMapNames; + HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP ); + for( ; anIterator.More(); anIterator.Next() ) { - anObjectName = myEditedObject->GetName(); + Handle(HYDROData_LandCoverMap) aLandCoverObj = + Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() ); + if ( !aLandCoverObj.IsNull() ) + aLandCoverMapNames.append( aLandCoverObj->GetName() ); + } + + //aLandCoverMapNames.sort(); + aPanel->setObjectNames( aLandCoverMapNames ); - // Construct a list of names of all land cover map objects defined within the data model - QStringList aLandCoverMapNames; - HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP ); - for( ; anIterator.More(); anIterator.Next() ) + if ( myEditedObject.IsNull() ) + { + if ( !aLandCoverMapNames.empty() ) { - Handle(HYDROData_LandCoverMap) aLandCoverObj = - Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() ); - if ( !aLandCoverObj.IsNull() ) - aLandCoverMapNames.append( aLandCoverObj->GetName() ); + anObjectName = aLandCoverMapNames.first(); + if ( !anObjectName.isEmpty()) + { + Handle(HYDROData_LandCoverMap) anObject = + Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), anObjectName ) ); + if( !anObject.IsNull() ) + myEditedObject = anObject; + } } - - //aLandCoverMapNames.sort(); - aPanel->setObjectNames( aLandCoverMapNames ); } + else + anObjectName = myEditedObject->GetName(); } aPanel->setObjectName( anObjectName ); - + + closePreview(); + if ( myOperationId != CreateLandCoverMapId ) + onCreatePreview(); + aPanel->blockSignals( false ); + + module()->update( UF_OCCViewer | UF_FitAll ); } void HYDROGUI_LandCoverMapOp::abortOperation() @@ -108,6 +156,10 @@ void HYDROGUI_LandCoverMapOp::abortOperation() closePreview(); HYDROGUI_Operation::abortOperation(); + + SalomeApp_Study* aStudy = dynamic_cast( module()->getApp()->activeStudy() ); + if ( aStudy ) + module()->update( UF_OCCViewer | UF_FitAll ); } void HYDROGUI_LandCoverMapOp::commitOperation() @@ -115,17 +167,17 @@ void HYDROGUI_LandCoverMapOp::commitOperation() closePreview(); HYDROGUI_Operation::commitOperation(); + + module()->update( UF_OCCViewer | UF_FitAll ); } HYDROGUI_InputPanel* HYDROGUI_LandCoverMapOp::createInputPanel() const { HYDROGUI_LandCoverMapDlg* aPanel = new HYDROGUI_LandCoverMapDlg( module(), getName(), myOperationId ); - /* - connect( aPanel, SIGNAL( CreatePreview( const QStringList& ) ), - this, SLOT( onCreatePreview( const QStringList& ) ) ); - connect( aPanel, SIGNAL( addPolylines() ), SLOT( onAddPolylines() ) ); - connect( aPanel, SIGNAL( removePolylines() ), SLOT( onRemovePolylines() ) ); - */ + connect( aPanel, SIGNAL( landCoverMapChanged( const QString& ) ), + this, SLOT( onLandCoverMapChanged( const QString& ) ) ); + connect( aPanel, SIGNAL( polylineFaceChanged() ), + this, SLOT( onPolylineFaceChanged() ) ); return aPanel; } @@ -156,9 +208,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,10 +225,22 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, return false; } } + // Get face(s) selected in the 3d viewer + else if ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) + { + if ( myPreviewPrs ) + // Fill in aFacesSelectedInViewer list + getSelectedShapes( aFacesSelectedInViewer ); + } // Get selected Strickler type QString aSelectedStricklerType; - if ( myOperationId == CreateLandCoverMapId || myOperationId == AddLandCoverId || myOperationId == MergeLandCoverId ) + if ( myOperationId == CreateLandCoverMapId || + myOperationId == AddLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) { aSelectedStricklerType = aPanel->getSelectedStricklerTypeName(); if ( aSelectedStricklerType.isEmpty() ) @@ -186,10 +253,16 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, // Create / find the new / edited land cover map object Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject : Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) ); + if ( aLandCoverMapObj.IsNull() ) + { + theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" ); + return false; + } // 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 +276,88 @@ 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 ) { - if ( !anError.IsEmpty() ) { - theErrorMsg = HYDROGUI_Tool::ToQString( anError ); - } else { - theErrorMsg = tr( "LAND_COVER_OBJECT_CANNOT_BE_CREATED" ); + bool aLandCoverRemoved = false; + if ( !aFacesSelectedInViewer.IsEmpty() ) + { + aLandCoverRemoved = aLandCoverMapObj->Remove( aFacesSelectedInViewer ); + if ( !aLandCoverRemoved ) + { + theErrorMsg = tr( "LAND_COVER_NOT_REMOVED" ); + return false; + } } - return false; - }*/ + } + + // Split land cover(s) inside edited land cover map + if ( myOperationId == SplitLandCoverId ) + { + bool aLandCoverSplit = false; + if ( !aPolyline.IsNull() ) + aLandCoverSplit = aLandCoverMapObj->Split( aPolyline ); + else if ( !aFace.IsNull() ) + { + // Get the complete boundary of the object face as the splitting polyline + QList aBoundShapes; + QStringList aBoundNames; + aFace->GetBoundaries( aBoundShapes, aBoundNames ); + + for( int i=0, n=aBoundShapes.size(); iSetFillingColor( aLandCoverMapObj->DefaultFillingColor() ); - aLandCoverMapObj->SetBorderColor( aLandCoverMapObj->DefaultBorderColor() ); - }*/ + bool aSplitResult = aLandCoverMapObj->Split( aShape ); + aLandCoverSplit = ( i==0 ? aSplitResult : aLandCoverSplit && aSplitResult ); + } + } + if ( !aLandCoverSplit ) + { + theErrorMsg = tr( "LAND_COVER_NOT_SPLIT" ); + return false; + } + } - //aLandCoverMapObj->SetPolylines( aZonePolylines ); - //aLandCoverMapObj->SetStricklerType( aSelectedStricklerType ); + // 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; + } + } + } + + // 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(); closePreview(); + // Publish the newly created land cover map in the Object Browser module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), aLandCoverMapObj, true ); if ( myOperationId == CreateLandCoverMapId ) { @@ -234,36 +365,122 @@ 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(); theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + if ( myOperationId == CreateLandCoverMapId ) + module()->enableLCMActions(); + 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 + closePreview(); + onCreatePreview(); + } + } +} + +void HYDROGUI_LandCoverMapOp::onPolylineFaceChanged() { - /* - 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++ ) + LightApp_DataOwner* aPolylineFaceDataOwner = NULL; + Handle(HYDROData_Entity) aPolylineFace = aPanel->getPolylineFace(); + if ( !aPolylineFace.IsNull() ) { - QString aPolylineName = *anIt; - Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINEXY ) ); - if ( !aPolyline.IsNull() ) - aZonePolylines.Append( aPolyline ); + // Select chosen polyline/face in the Object Browser, if it is not selected yet + // (i.e. object was chosen not in the Object Browser or 3d Viewer, but in combo-box) + aPolylineFaceDataOwner = new LightApp_DataOwner( HYDROGUI_DataObject::dataObjectEntry( aPolylineFace ) ); + LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr(); + if ( aSelectionMgr ) + { + bool bIsAlreadySelected = false; + SUIT_DataOwnerPtrList aSelectedOwners; + aSelectionMgr->selected( aSelectedOwners ); + foreach( SUIT_DataOwner* aSUITOwner, aSelectedOwners ) + { + if ( LightApp_DataOwner* anOwner = dynamic_cast( aSUITOwner ) ) + { + if ( anOwner->entry() == aPolylineFaceDataOwner->entry() ) + { + bIsAlreadySelected = true; + break; + } + } + } + if ( !bIsAlreadySelected ) + { + SUIT_DataOwnerPtrList aList( true ); + aList.append( SUIT_DataOwnerPtr( aPolylineFaceDataOwner ) ); + aSelectionMgr->setSelected( aList ); + } + } + + // Show Preview of selected polyline/face + Handle(HYDROData_PolylineXY) aPolyline = Handle(HYDROData_PolylineXY)::DownCast( aPolylineFace ); + Handle(HYDROData_Object) aFace = Handle(HYDROData_Object)::DownCast( aPolylineFace ); + if ( !aPolyline.IsNull() || !aFace.IsNull() ) + { + TopoDS_Shape aTopoDSShape; + if ( !aPolyline.IsNull() ) + aTopoDSShape = aPolyline->GetShape(); + else + aTopoDSShape = aFace->GetTopShape(); + + OCCViewer_ViewManager* aViewManager = ::qobject_cast( + module()->getApp()->getViewManager( OCCViewer_Viewer::Type(), true ) ); + if ( aViewManager ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + if ( myPolylineFacePreviewPrs ) + { + delete myPolylineFacePreviewPrs; + myPolylineFacePreviewPrs = 0; + } + + int aViewerId = (size_t)aViewer; + if ( !module()->isObjectVisible( aViewerId, aPolylineFace ) ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + { + myPolylineFacePreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + aCtx->ClearSelected(); + + myPolylineFacePreviewPrs->setBorderColor( Qt::white, false, false ); + myPolylineFacePreviewPrs->setShape( aTopoDSShape, true, true, !aPolyline.IsNull() ? AIS_WireFrame : AIS_Shaded ); + + module()->update( UF_OCCViewer | UF_FitAll ); + } + } + } + } + } } - - TCollection_AsciiString anError; - TopoDS_Shape aZoneShape = HYDROData_LandCover::buildShape( aZonePolylines, anError ); +} + +void HYDROGUI_LandCoverMapOp::onCreatePreview() +{ + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + QApplication::setOverrideCursor( Qt::WaitCursor ); LightApp_Application* anApp = module()->getApp(); if ( !getPreviewManager() ) @@ -276,35 +493,295 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview( const QStringList& thePolylineNam { Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); if ( !aCtx.IsNull() ) - myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + { + if ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) + { + disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + + connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + + LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr(); + if ( aSelectionMgr ) + { + QList aSelectorList; + aSelectionMgr->selectors( aViewManager->getType(), aSelectorList ); + QList::iterator anIter, anIterEnd = aSelectorList.end(); + for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ ) + { + HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast( *anIter ); + if ( aHydroSelector ) + { + disconnect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) ); + connect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) ); + } + } + } + + connect( this, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); + } + else + connect( aViewer, SIGNAL( selectionChanged() ), this, SLOT( onViewerSelectionChanged() ) ); + myPreviewPrs = new HYDROGUI_ShapeLandCoverMap( module()->getOCCDisplayer(), aCtx, myEditedObject, getPreviewZLayer()/*, theIsScalarMapMode*/ ); + } + } + } + + if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() ) + { + 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 ); + + QApplication::restoreOverrideCursor(); +} + +void HYDROGUI_LandCoverMapOp::onViewerSelectionChanged() +{ + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + 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 == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + { + if ( aNbSelected == 1 && !myEditedObject.IsNull() ) + { + TopTools_ListOfShape aFacesSelectedInViewer; + getSelectedShapes( aFacesSelectedInViewer ); + if ( aFacesSelectedInViewer.Extent() == 1 ) + { + QString aType = myEditedObject->StricklerType( TopoDS::Face( aFacesSelectedInViewer.First() ) ); + if ( !aType.isEmpty() ) + aPanel->setSelectedStricklerTypeName( aType ); + } } } - if ( aViewManager && myPreviewPrs ) + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + aPanel->updateSelectedLandCoversLabel( aNbSelected ); +} + +void HYDROGUI_LandCoverMapOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y()); +} + +void HYDROGUI_LandCoverMapOp::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + if (theEvent->button() != Qt::LeftButton) return; + if (!theWindow->inherits("OCCViewer_ViewWindow")) return; + + OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow; + if (!aView ) + return; + + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( !aViewManager ) + return; + + OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer(); + if ( !aViewer ) + return; + + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( aCtx.IsNull() ) + return; + + myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y()); + + if (myStartPnt == myEndPnt) { - QColor aFillingColor = Qt::magenta; - QColor aBorderColor = Qt::transparent; - if ( !myEditedObject.IsNull() ) { - aFillingColor = myEditedObject->GetFillingColor(); - aBorderColor = myEditedObject->GetBorderColor(); + if ( !aViewer->isPreselectionEnabled() ) { + Handle(V3d_View) aView3d = aView->getViewPort()->getView(); + if ( !aView3d.IsNull() ) { + aCtx->MoveTo(myEndPnt.x(), myEndPnt.y(), aView3d); + } } - myPreviewPrs->setFillingColor( aFillingColor, false, false ); - myPreviewPrs->setBorderColor( aBorderColor, false, false ); + Handle(StdSelect_ViewerSelector3d) aMainSelector = aCtx->MainSelector(); + if ( aMainSelector.IsNull() ) + return; + const Standard_Integer aDetectedNb = aMainSelector->NbPicked(); + if ( aDetectedNb == 0 ) + { + aCtx->ClearSelected( false ); + emit deselection(); + } - if( !aZoneShape.IsNull() ) - myPreviewPrs->setShape( aZoneShape ); + for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) + { + Handle(SelectMgr_EntityOwner) anOwner = aMainSelector->Picked (aDetIter); + aCtx->AddOrRemoveSelected( anOwner, Standard_False ); + } + } + else + { + aCtx->ShiftSelect(myStartPnt.x(), myStartPnt.y(), + myEndPnt.x(), myEndPnt.y(), + aView->getViewPort()->getView(), Standard_False ); } - QApplication::restoreOverrideCursor(); - */ + aCtx->UpdateCurrentViewer(); + emit selectionChanged(); } void HYDROGUI_LandCoverMapOp::closePreview() { - if( myPreviewPrs ) + if ( myPreviewPrs ) { delete myPreviewPrs; myPreviewPrs = 0; } + + if ( myPolylineFacePreviewPrs ) + { + delete myPolylineFacePreviewPrs; + myPolylineFacePreviewPrs = 0; + } + + HYDROGUI_LandCoverMapDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + if ( myOperationId == RemoveLandCoverId || myOperationId == MergeLandCoverId || myOperationId == ChangeLandCoverTypeId ) + aPanel->setApplyEnabled( false ); + + if ( myOperationId == RemoveLandCoverId || + myOperationId == MergeLandCoverId || + myOperationId == ChangeLandCoverTypeId ) + { + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( aViewManager ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + disconnect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*))); + + LightApp_SelectionMgr* aSelectionMgr = module()->getApp()->selectionMgr(); + if ( aSelectionMgr ) + { + QList aSelectorList; + aSelectionMgr->selectors( aViewManager->getType(), aSelectorList ); + QList::iterator anIter, anIterEnd = aSelectorList.end(); + for( anIter = aSelectorList.begin(); anIter != anIterEnd; anIter++ ) + { + HYDROGUI_OCCSelector* aHydroSelector = dynamic_cast( *anIter ); + if ( aHydroSelector ) + { + disconnect( this, SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) ); + connect( aHydroSelector->viewer(), SIGNAL( deselection() ), aHydroSelector, SLOT( onDeselection() ) ); + } + } + } + } + } + } +} + +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; +} + +void HYDROGUI_LandCoverMapOp::getSelectedShapes( TopTools_ListOfShape& theSelectedShapes ) +{ + Handle(AIS_InteractiveContext) aCtx = getInteractiveContext(); + if ( !aCtx.IsNull() ) + { + for ( aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected() ) + { + TopoDS_Shape aSelectedShape = aCtx->SelectedShape(); + if ( aSelectedShape.IsNull() ) + continue; + + theSelectedShapes.Append( aSelectedShape ); + } + } +} + +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(); + } }