From 9429dfaa77cbf34d60f31162951da52437c63eb9 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 19 Jun 2015 11:15:24 +0300 Subject: [PATCH] refs #585: preview in split operation --- src/HYDROGUI/HYDROGUI_ObjComboBox.cxx | 3 + src/HYDROGUI/HYDROGUI_ObjListBox.cxx | 3 + src/HYDROGUI/HYDROGUI_ObjListBox.h | 3 + src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx | 57 ++++++++++- src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h | 16 +++ src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx | 103 +++++++++++++++++++- src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h | 11 +++ 7 files changed, 193 insertions(+), 3 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_ObjComboBox.cxx b/src/HYDROGUI/HYDROGUI_ObjComboBox.cxx index 18639114..13c88f05 100644 --- a/src/HYDROGUI/HYDROGUI_ObjComboBox.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjComboBox.cxx @@ -122,7 +122,10 @@ QStringList HYDROGUI_ObjComboBox::objectNames( HYDROData_SequenceOfObjects& theO for ( HYDROData_Iterator it( HYDROData_Document::Document( module()->getStudyId() ), objectType() ); it.More(); it.Next() ) { if ( !objectFilter() || objectFilter()->isOk( it.Current() ) ) + { + theObjects.Append( it.Current() ); aNames.append( it.Current()->GetName() ); + } } return aNames; } diff --git a/src/HYDROGUI/HYDROGUI_ObjListBox.cxx b/src/HYDROGUI/HYDROGUI_ObjListBox.cxx index f20715a6..f63b7fdf 100644 --- a/src/HYDROGUI/HYDROGUI_ObjListBox.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjListBox.cxx @@ -94,6 +94,7 @@ void HYDROGUI_ObjListBox::reset() { myList->clear(); mySelection.Clear(); + emit selectionChanged(); } void HYDROGUI_ObjListBox::setSelectedObjects( const HYDROData_SequenceOfObjects& theObjects ) @@ -115,6 +116,7 @@ HYDROData_SequenceOfObjects HYDROGUI_ObjListBox::selectedObjects() const void HYDROGUI_ObjListBox::OnInclude() { Append( HYDROGUI_Tool::GetSelectedObjects( module() ) ); + emit selectionChanged(); } void HYDROGUI_ObjListBox::OnExclude() @@ -126,6 +128,7 @@ void HYDROGUI_ObjListBox::OnExclude() myList->takeItem( anIndex ); mySelection.Remove( anIndex, anIndex ); } + emit selectionChanged(); } void HYDROGUI_ObjListBox::Append( const HYDROData_SequenceOfObjects& theObjects ) diff --git a/src/HYDROGUI/HYDROGUI_ObjListBox.h b/src/HYDROGUI/HYDROGUI_ObjListBox.h index 7d599dd3..ddb4da28 100644 --- a/src/HYDROGUI/HYDROGUI_ObjListBox.h +++ b/src/HYDROGUI/HYDROGUI_ObjListBox.h @@ -51,6 +51,9 @@ public: private: void Init(const QString& theTitle); +signals: + void selectionChanged(); + private slots: void OnInclude(); void OnExclude(); diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx index ddc0a44d..6fe87987 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.cxx @@ -20,15 +20,25 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include #include #include +#include #include +const double MIN_COORD = -1000000; +const double MAX_COORD = 1000000; +const double STEP = 10; + HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ), myOCCViewer( 0 ) { QFrame* aFrame = new QFrame( mainFrame() ); addWidget( aFrame, 1 ); @@ -43,7 +53,11 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu QFrame* aPointPage = new QFrame(); myMainPolyline1 = new HYDROGUI_ObjComboBox( theModule, tr( "POLYLINE" ), KIND_POLYLINEXY, aPointPage ); myX = new QtxDoubleSpinBox( aPointPage ); + myX->setRange( MIN_COORD, MAX_COORD ); + myX->setSingleStep( STEP ); myY = new QtxDoubleSpinBox( aPointPage ); + myY->setRange( MIN_COORD, MAX_COORD ); + myY->setSingleStep( STEP ); QGridLayout* aPointPageLayout = new QGridLayout( aPointPage ); aPointPageLayout->addWidget( myMainPolyline1, 0, 0, 1, 3 ); @@ -70,6 +84,14 @@ HYDROGUI_SplitPolylinesDlg::HYDROGUI_SplitPolylinesDlg( HYDROGUI_Module* theModu QGridLayout* aSplitPageLayout = new QGridLayout( aSplitPage ); aSplitPageLayout->addWidget( myPolylines, 0, 0 ); myTab->addTab( aSplitPage, tr( "COMPLETE_SPLIT" ) ); + + connect( myX, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) ); + connect( myY, SIGNAL( valueChanged( double ) ), this, SIGNAL( pointMoved() ) ); + connect( myTab, SIGNAL( currentChanged( int ) ), this, SIGNAL( modeChanged() ) ); + connect( myMainPolyline1, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) ); + connect( myMainPolyline2, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) ); + connect( myToolPolyline, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( selectionChanged() ) ); + connect( myPolylines, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); } HYDROGUI_SplitPolylinesDlg::~HYDROGUI_SplitPolylinesDlg() @@ -117,6 +139,10 @@ HYDROData_SequenceOfObjects HYDROGUI_SplitPolylinesDlg::GetPolylines() const void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection() { + myMainPolyline1->reset(); + myMainPolyline2->reset(); + myPolylines->reset(); + Handle( HYDROData_Entity ) anObject = HYDROGUI_Tool::GetSelectedObject( module() ); if( anObject.IsNull() || anObject->GetKind() != KIND_POLYLINEXY ) return; @@ -126,3 +152,32 @@ void HYDROGUI_SplitPolylinesDlg::setPolylinesFromSelection() myMainPolyline2->setObjectName( aName ); myPolylines->setObjectsFromSelection(); } + +void HYDROGUI_SplitPolylinesDlg::setOCCViewer( OCCViewer_Viewer* theViewer ) +{ + if( !theViewer ) + return; + + myOCCViewer = theViewer; + OCCViewer_ViewManager* aViewManager = dynamic_cast( myOCCViewer->getViewManager() ); + disconnect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); + connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ), + this, SLOT( onMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) ); +} + +void HYDROGUI_SplitPolylinesDlg::onMousePress( SUIT_ViewWindow* theWindow, QMouseEvent* theEvent ) +{ + gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), getViewPort()->getView() ); + myX->setValue( aPnt.X() ); + myY->setValue( aPnt.Y() ); +} + +OCCViewer_ViewPort3d* HYDROGUI_SplitPolylinesDlg::getViewPort() const +{ + OCCViewer_ViewPort3d* aViewPort = 0; + if ( myOCCViewer ) + aViewPort = dynamic_cast( myOCCViewer->getViewManager()->getActiveView() )->getViewPort(); + + return aViewPort; +} diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h index 0d09934e..c550472a 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesDlg.h @@ -27,6 +27,9 @@ class QtxDoubleSpinBox; class HYDROGUI_ObjComboBox; class HYDROGUI_ObjListBox; class gp_Pnt2d; +class OCCViewer_Viewer; +class SUIT_ViewWindow; +class OCCViewer_ViewPort3d; class HYDROGUI_SplitPolylinesDlg : public HYDROGUI_InputPanel { @@ -46,6 +49,18 @@ public: HYDROData_SequenceOfObjects GetPolylines() const; void setPolylinesFromSelection(); + void setOCCViewer( OCCViewer_Viewer* theViewer ); + +signals: + void modeChanged(); + void pointMoved(); + void selectionChanged(); + +private slots: + void onMousePress( SUIT_ViewWindow*, QMouseEvent* ); + +private: + OCCViewer_ViewPort3d* getViewPort() const; private: QTabWidget* myTab; @@ -55,6 +70,7 @@ private: HYDROGUI_ObjComboBox* myMainPolyline2; HYDROGUI_ObjComboBox* myToolPolyline; HYDROGUI_ObjListBox* myPolylines; + OCCViewer_Viewer* myOCCViewer; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index 07a49d3b..afb40918 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -18,12 +18,22 @@ #include #include +#include #include +#include #include +#include +#include +#include #include +#include +#include +#include +#include HYDROGUI_SplitPolylinesOp::HYDROGUI_SplitPolylinesOp( HYDROGUI_Module* theModule ) -: HYDROGUI_Operation( theModule ) +: HYDROGUI_Operation( theModule ), + myPreviewPrs( 0 ) { setName( tr( "SPLIT_POLYLINES" ) ); } @@ -42,12 +52,22 @@ void HYDROGUI_SplitPolylinesOp::startOperation() return; aPanel->setPolylinesFromSelection(); + LightApp_Application* anApp = module()->getApp(); + OCCViewer_ViewManager* aViewManager = + dynamic_cast( anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + aPanel->setOCCViewer( aViewManager ? aViewManager->getOCCViewer() : 0 ); + setPreviewManager( aViewManager ); + OnUpdatePreview(); } HYDROGUI_InputPanel* HYDROGUI_SplitPolylinesOp::createInputPanel() const { - return new HYDROGUI_SplitPolylinesDlg( module(), getName() ); + HYDROGUI_SplitPolylinesDlg* aDlg = new HYDROGUI_SplitPolylinesDlg( module(), getName() ); + connect( aDlg, SIGNAL( pointMoved() ), this, SLOT( OnUpdatePreview() ) ); + connect( aDlg, SIGNAL( modeChanged() ), this, SLOT( OnUpdatePreview() ) ); + connect( aDlg, SIGNAL( selectionChanged() ), this, SLOT( OnUpdatePreview() ) ); + return aDlg; } bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags, @@ -80,3 +100,82 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags, theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } + +void HYDROGUI_SplitPolylinesOp::abortOperation() +{ + erasePreview(); + HYDROGUI_Operation::abortOperation(); +} + +void HYDROGUI_SplitPolylinesOp::commitOperation() +{ + erasePreview(); + HYDROGUI_Operation::commitOperation(); +} + +void HYDROGUI_SplitPolylinesOp::erasePreview() +{ + if( myPreviewPrs ) + { + delete myPreviewPrs; + myPreviewPrs = 0; + } +} + +void HYDROGUI_SplitPolylinesOp::OnUpdatePreview() +{ + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( aViewManager ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + { + if( !myPreviewPrs ) + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + aCtx->ClearSelected(); + } + } + } + + HYDROGUI_SplitPolylinesDlg* aPanel = ::qobject_cast( inputPanel() ); + if( myPreviewPrs && aPanel ) + { + BRep_Builder aBB; + TopoDS_Compound aCmp; + aBB.MakeCompound( aCmp ); + + switch( aPanel->GetMode() ) + { + case HYDROGUI_SplitPolylinesDlg::ByPoint: + { + gp_Pnt2d aPnt = aPanel->GetPoint(); + TopoDS_Vertex aVertex = BRepLib_MakeVertex( gp_Pnt( aPnt.X(), aPnt.Y(), 0.0 ) ); + aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() ); + aBB.Add( aCmp, aVertex ); + break; + } + case HYDROGUI_SplitPolylinesDlg::ByTool: + { + aBB.Add( aCmp, aPanel->GetMainPolyline()->GetShape() ); + aBB.Add( aCmp, aPanel->GetToolPolyline()->GetShape() ); + break; + } + case HYDROGUI_SplitPolylinesDlg::Split: + { + HYDROData_SequenceOfObjects aPolylines = aPanel->GetPolylines(); + for( int i=aPolylines.Lower(), n=aPolylines.Upper(); i<=n; i++ ) + { + Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( aPolylines.Value( i ) ); + if( !aPolyline.IsNull() ) + aBB.Add( aCmp, aPolyline->GetShape() ); + } + break; + } + } + + + myPreviewPrs->setShape( aCmp ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h index e2454a54..8de00f8b 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.h @@ -31,11 +31,22 @@ public: protected: virtual void startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); virtual HYDROGUI_InputPanel* createInputPanel() const; virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ); + + virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; }; + +protected slots: + void OnUpdatePreview(); + void erasePreview(); + +private: + HYDROGUI_Shape* myPreviewPrs; }; #endif -- 2.39.2