X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_SplitPolylinesOp.cxx;h=439af525d241b750406b745d50a5047f23d6d000;hb=41550a623dca7d2de1b388c9832fe3642d2b8753;hp=73f415a8957783ee7e0e6d81bb8eef3f32855fb4;hpb=91509fc95d80a88365f84eb941df6139d8a87dde;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index 73f415a8..439af525 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -22,24 +22,36 @@ #include #include #include +#include #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() @@ -78,22 +90,34 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags, if ( !aPanel ) return false; + //TODO: QString aName = aPanel->GetResultName(); Handle( HYDROData_PolylineXY ) aMainPolyline = aPanel->GetMainPolyline(); Handle( HYDROData_PolylineXY ) aToolPolyline = aPanel->GetToolPolyline(); HYDROData_SequenceOfObjects aPolylinesList = aPanel->GetPolylines(); gp_Pnt2d aPoint = aPanel->GetPoint(); + double aTolerance = 1E-2; //TODO HYDROData_PolylineOperator anOp; switch( aPanel->GetMode() ) { case HYDROGUI_SplitPolylinesDlg::ByPoint: - anOp.Split( aMainPolyline, aPoint ); + anOp.Split( doc(), aMainPolyline, aPoint, aTolerance ); break; case HYDROGUI_SplitPolylinesDlg::ByTool: - anOp.Split( aMainPolyline, aToolPolyline ); + { + bool isIntersected = false; + anOp.Split( doc(), aMainPolyline, aToolPolyline, aTolerance, isIntersected); + + if (!isIntersected) + { + const QString aTitle = tr("SPLIT_POLYLINE_BY_TOOL_WARNING_TITLE"); + const QString aMsg = tr("SPLIT_POLYLINE_BY_TOOL_WARNING_MSG"); + SUIT_MessageBox::warning(module()->getApp()->desktop(), aTitle, aMsg); + } break; + } case HYDROGUI_SplitPolylinesDlg::Split: - anOp.Split( aPolylinesList ); + anOp.Split( doc(), aPolylinesList, aTolerance ); break; } @@ -120,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 ) { @@ -133,13 +191,44 @@ void HYDROGUI_SplitPolylinesOp::OnUpdatePreview() if ( !aCtx.IsNull() ) { if( !myPreviewPrs ) + { myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); - aCtx->ClearSelected(); + 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(true); + } + + 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; @@ -182,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(); +}