From 392fa8e6fc49c5fad10b0e99281c129adca2dd51 Mon Sep 17 00:00:00 2001 From: mkr Date: Mon, 23 Nov 2015 20:56:02 +0300 Subject: [PATCH] refs #732: create preview of split point. --- src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx | 123 ++++++++++++++++++++- src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h | 8 ++ 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index cae14c9e..be1c18e3 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -26,24 +26,32 @@ #include #include #include +#include +#include #include #include +#include #include #include #include +#include #include #include #include +#include + HYDROGUI_SplitPolylinesOp::HYDROGUI_SplitPolylinesOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ), - myPreviewPrs( 0 ) + myPreviewPrs( 0 ), + mySplitPointPreview( 0 ) { setName( tr( "SPLIT_POLYLINES" ) ); } HYDROGUI_SplitPolylinesOp::~HYDROGUI_SplitPolylinesOp() { + erasePreview(); } void HYDROGUI_SplitPolylinesOp::startOperation() @@ -136,10 +144,44 @@ void HYDROGUI_SplitPolylinesOp::erasePreview() delete myPreviewPrs; myPreviewPrs = 0; } + + HYDROGUI_SplitPolylinesDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( aViewManager ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + if ( mySplitPointPreview ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + { + if ( aCtx->HasOpenedContext() ) + aCtx->CloseLocalContext(); + aCtx->Erase( mySplitPointPreview, Standard_False ); + } + mySplitPointPreview = 0; + } + + if ( aPanel->GetMode() == HYDROGUI_SplitPolylinesDlg::ByPoint ) + { + disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + } + } + } } void HYDROGUI_SplitPolylinesOp::OnUpdatePreview() { + HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast( inputPanel() ); + OCCViewer_ViewManager* aViewManager = getPreviewManager(); if ( aViewManager ) { @@ -151,14 +193,42 @@ void HYDROGUI_SplitPolylinesOp::OnUpdatePreview() if( !myPreviewPrs ) { myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); - myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_VERTEX ) ); + myPreviewPrs->setSelectionMode( AIS_Shape::SelectionMode( TopAbs_FACE ) ); + } + + if ( mySplitPointPreview ) + { + if ( aCtx->HasOpenedContext() ) + aCtx->CloseLocalContext(); + if ( aPanel->GetMode() == HYDROGUI_SplitPolylinesDlg::ByPoint ) + { + if ( !aCtx->IsDisplayed( mySplitPointPreview ) ) + aCtx->Display( mySplitPointPreview, Standard_False ); + } + else + aCtx->Erase( mySplitPointPreview, Standard_False ); } + aCtx->ClearSelected(); } + + if ( aPanel->GetMode() == HYDROGUI_SplitPolylinesDlg::ByPoint ) + { + disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + } + else + { + disconnect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + connect(aViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), + aViewer, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*))); + } } } - HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast( inputPanel() ); if( myPreviewPrs && aPanel ) { BRep_Builder aBB; @@ -201,3 +271,50 @@ void HYDROGUI_SplitPolylinesOp::OnUpdatePreview() myPreviewPrs->setShape( aCmp ); } } + +void HYDROGUI_SplitPolylinesOp::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent) +{ + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( !aViewManager ) + 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; + + OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer(); + if ( !aViewer ) + return; + + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( aCtx.IsNull() ) + return; + + gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), aView ); + BRep_Builder aBuilder; + TopoDS_Compound aShape; + aBuilder.MakeCompound(aShape); + aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex( aPnt ) ); + + if ( mySplitPointPreview ) + { + if ( aCtx->HasOpenedContext() ) + aCtx->CloseLocalContext(); + aCtx->Erase( mySplitPointPreview, Standard_False ); + } + + mySplitPointPreview = new AIS_Shape( aShape ); + if ( aCtx->HasOpenedContext() ) + aCtx->CloseLocalContext(); + aCtx->Display( mySplitPointPreview, Standard_False ); + + aCtx->UpdateCurrentViewer(); +} diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h index 8de00f8b..c81a69ab 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h @@ -21,6 +21,12 @@ #include "HYDROGUI_Operation.h" +class SUIT_ViewWindow; + +class AIS_Shape; + +class QMouseEvent; + class HYDROGUI_SplitPolylinesOp : public HYDROGUI_Operation { Q_OBJECT @@ -44,9 +50,11 @@ protected: protected slots: void OnUpdatePreview(); void erasePreview(); + void onMousePress(SUIT_ViewWindow*, QMouseEvent*); private: HYDROGUI_Shape* myPreviewPrs; + AIS_Shape* mySplitPointPreview; }; #endif -- 2.39.2