From c7cbb61c283aad32e1d97e5932868e74866ac257 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 29 Nov 2013 07:10:21 +0000 Subject: [PATCH] In order to create profile, connected to another widget(not OCC Viewer), the viewer functionality is separated into separate methods. --- src/HYDROCurveCreator/CurveCreator_Widget.cxx | 145 ++++++++++-------- src/HYDROCurveCreator/CurveCreator_Widget.h | 10 ++ 2 files changed, 93 insertions(+), 62 deletions(-) diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index fb6f53a3..1897434c 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -269,6 +269,57 @@ OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer() return myOCCViewer; } +/** + * Returns OCC viewer context + */ +Handle(AIS_InteractiveContext) CurveCreator_Widget::getAISContext() +{ + OCCViewer_Viewer* aViewer = getOCCViewer(); + return aViewer ? aViewer->getAISContext() : 0; +} + +/** + * Returns OCC viewer view port + */ +OCCViewer_ViewPort3d* CurveCreator_Widget::getViewPort() +{ + OCCViewer_ViewPort3d* aViewPort = 0; + OCCViewer_Viewer* aViewer = getOCCViewer(); + if ( aViewer ) + aViewPort = ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort(); + + return aViewPort; +} + +/** + * Set interaction style in the OCC viewer + * \param theStyle a new style + * \return the previous style + */ +int CurveCreator_Widget::changeInteractionStyle( int theStyle ) +{ + OCCViewer_Viewer* aViewer = getOCCViewer(); + if ( !aViewer ) + return -1; + + int aPrevStyle = aViewer->interactionStyle(); + aViewer->setInteractionStyle( theStyle ); + + return aPrevStyle; +} + +/** + * Set interaction style in the OCC viewer + * \param theStyle a new style + * \return the previous style + */ +void CurveCreator_Widget::setObjectsSelected(const AIS_ListOfInteractive& theList) +{ + OCCViewer_Viewer* aViewer = getOCCViewer(); + if ( aViewer ) + aViewer->setObjectsSelected(theList); +} + //======================================================================= // function: getUniqSectionName // purpose: return unique section name @@ -401,26 +452,12 @@ void CurveCreator_Widget::onSelectionChanged() void CurveCreator_Widget::onAdditionMode(bool checked) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if( !myCurve || !aViewer ) + if (!checked) return; - Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); - OCCViewer_ViewManager* aViewManager = dynamic_cast - (aViewer->getViewManager()); -// if ( aViewManager->getType() == OCCViewer_Viewer::Type() ) { - if( aViewer ) { - if (checked) { -/* myGuiState = aViewWindow->saveState(); - aViewer->enableMultiselection(false); - aViewer->enableSelection(false);*/ - } else { -/* aViewer->enableMultiselection(true); - aViewer->enableSelection(true); - aViewWindow->restoreState( myGuiState );*/ - return; - } - } + Handle(AIS_InteractiveContext) aContext = getAISContext(); + if( !myCurve || !aContext ) + return; mySection= -1; myPointNum = -1; @@ -875,10 +912,9 @@ void CurveCreator_Widget::onGetCoordsByClick( QMouseEvent* pe ) return; if ( pe->modifiers() != Qt::ControlModifier ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) - return; - Handle(AIS_InteractiveContext) ic = aViewer->getAISContext(); + Handle(AIS_InteractiveContext) ic = getAISContext(); + if ( !ic ) + return; gp_Pnt aPnt; @@ -898,8 +934,7 @@ void CurveCreator_Widget::onGetCoordsByClick( QMouseEvent* pe ) aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) ); else*/ { - OCCViewer_ViewPort3d* vp = - ((OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView())->getViewPort(); + OCCViewer_ViewPort3d* vp = getViewPort(); aPnt = CurveCreator_Utils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); } // set the coordinates into dialog @@ -1059,14 +1094,13 @@ void CurveCreator_Widget::removePoint() void CurveCreator_Widget::insertPointToSelectedSegment( const int theX, const int theY ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + Handle(AIS_InteractiveContext) aContext = getAISContext(); + if ( !aContext ) return; - gp_Pnt aPoint; gp_Pnt aPoint1, aPoint2; bool isFoundPoint = false; - Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); + for ( aContext->InitSelected(); aContext->MoreSelected() && !isFoundPoint; aContext->NextSelected() ) { TopoDS_Shape aTShape = aContext->SelectedShape(); @@ -1130,20 +1164,18 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX, void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, const int theYPosition ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + OCCViewer_ViewPort3d* aViewPort = getViewPort(); + if ( !aViewPort ) return; SectionToPointList aPoints; startCurveModification( aPoints, false ); - OCCViewer_ViewWindow* aWindow = - (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView(); gp_Pnt aStartPnt = CurveCreator_Utils::ConvertClickToPoint( myDragStartPosition.x(), - myDragStartPosition.y(), - aWindow->getViewPort()->getView() ); + myDragStartPosition.y(), + aViewPort->getView() ); gp_Pnt anEndPnt = CurveCreator_Utils::ConvertClickToPoint( theXPosition, theYPosition, - aWindow->getViewPort()->getView() ); + aViewPort->getView() ); double aXDelta = aStartPnt.X() - anEndPnt.X(); double anYDelta = aStartPnt.Y() - anEndPnt.Y(); @@ -1171,10 +1203,9 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, void CurveCreator_Widget::updateLocalPointView() { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + Handle(AIS_InteractiveContext) aContext = getAISContext(); + if ( !aContext ) return; - Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext(); bool isBlocked = myLocalPointView->blockSignals(true); gp_Pnt aPnt; @@ -1221,10 +1252,9 @@ void CurveCreator_Widget::updateLocalPointView() */ void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool isUpdateTable ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + Handle(AIS_InteractiveContext) ic = getAISContext(); + if ( !ic ) return; - Handle(AIS_InteractiveContext) ic = aViewer->getAISContext(); if ( theOpen ) { // Open local context if there is no one @@ -1327,20 +1357,18 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double */ void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); if ( theState ) { getSelectedPonts( myDragPoints ); myDragStarted = myDragPoints.size(); myDragStartPosition = thePoint; - if ( aViewer && myDragStarted ) { + if ( myDragStarted ) { // change a viewer interaction style in order to avoid a select rectangle build - myDragInteractionStyle = aViewer->interactionStyle(); - aViewer->setInteractionStyle(SUIT_ViewModel::KEY_FREE); + myDragInteractionStyle = changeInteractionStyle( SUIT_ViewModel::KEY_FREE ); } } else { - if ( aViewer && myDragStarted ) - aViewer->setInteractionStyle( myDragInteractionStyle ); + if ( myDragStarted ) + changeInteractionStyle( myDragInteractionStyle ); myDragStarted = false; myDragPoints.clear(); } @@ -1356,16 +1384,11 @@ void CurveCreator_Widget::getSelectedPonts( CurveCreator_Widget::SectionToPointL void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionToPointList& thePoints ) { - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + Handle(AIS_InteractiveContext) ic = getAISContext(); + if ( !ic || !ic->HasOpenedContext() ) return; AIS_ListOfInteractive aListToSelect; - - Handle(AIS_InteractiveContext) ic = aViewer->getAISContext(); - if ( !ic->HasOpenedContext() ) - return; - AIS_ListOfInteractive aDisplayedList; ic->DisplayedObjects( aDisplayedList ); @@ -1404,7 +1427,7 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionTo } ic->ClearSelected( Standard_False ); - aViewer->setObjectsSelected( aListToSelect ); + setObjectsSelected( aListToSelect ); updateLocalPointView(); } @@ -1517,8 +1540,8 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject { bool isFound = false; - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( theObject.IsNull() || !aViewer ) + Handle(AIS_InteractiveContext) aContext = getAISContext(); + if ( theObject.IsNull() || !aContext ) return isFound; gp_Pnt aPoint; @@ -1596,13 +1619,11 @@ bool CurveCreator_Widget::hasProjectPointOnCurve( const int theX, const int theY Standard_Real& theParameter ) { bool isFound = false; - OCCViewer_Viewer* aViewer = getOCCViewer(); - if ( !aViewer ) + OCCViewer_ViewPort3d* aViewPort = getViewPort(); + if ( !aViewPort ) return isFound; - OCCViewer_ViewWindow* aWindow = - (OCCViewer_ViewWindow*)aViewer->getViewManager()->getActiveView(); - Handle(V3d_View) aView = aWindow->getViewPort()->getView(); + Handle(V3d_View) aView = aViewPort->getView(); gp_Pnt aPoint = CurveCreator_Utils::ConvertClickToPoint( theX, theY, aView ); GeomAPI_ProjectPointOnCurve aProj( aPoint, theCurve ); diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index 72b3d64a..ea41a275 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -29,12 +29,16 @@ #include #include +#include #include #include #include class OCCViewer_Viewer; +class OCCViewer_ViewPort3d; + +class AIS_ListOfInteractive; class QAction; class QPixmap; @@ -52,9 +56,15 @@ public: CurveCreator_ICurve *theCurve, Qt::WindowFlags fl=0 ); + // OCC viewer manipulation void setOCCViewer( OCCViewer_Viewer* theViewer ); OCCViewer_Viewer* getOCCViewer(); + Handle(AIS_InteractiveContext) getAISContext(); + OCCViewer_ViewPort3d* getViewPort(); + int changeInteractionStyle( int theStyle ); + void setObjectsSelected(const AIS_ListOfInteractive& theList); + //! Return unique section name std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const; -- 2.39.2