X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_Displayer.cxx;h=7614db2affce28d64f1c85c1fbaad28ce8d2a5e2;hb=a300fde9adcb04f1d57269c2849e7337a6d3d4a3;hp=d42b31423cc094855c8bf18a243f2a7626bf62de;hpb=026402739f8239caa8c470c19402ce379d17b9d7;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_Displayer.cxx b/src/HYDROGUI/HYDROGUI_Displayer.cxx index d42b3142..7614db2a 100644 --- a/src/HYDROGUI/HYDROGUI_Displayer.cxx +++ b/src/HYDROGUI/HYDROGUI_Displayer.cxx @@ -30,11 +30,27 @@ #include "HYDROGUI_PrsZoneDriver.h" #include "HYDROGUI_Tool.h" +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + #include #include +const double LOCAL_SELECTION_TOLERANCE = 0.0001; + HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule ) -: HYDROGUI_AbstractDisplayer( theModule ) +: HYDROGUI_AbstractDisplayer( theModule ), + myXPosition( -1 ), myYPosition( -1 ), myIsPositionSaved( false ) { } @@ -108,6 +124,7 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs, if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) ) { aViewPort->removeItem( aPrs ); + anObjectList.removeAll( aPrs ); delete aPrs; } } @@ -116,7 +133,8 @@ void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs, void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, const int theViewerId, - const bool theIsForced ) + const bool theIsForced, + const bool theDoFitAll) { GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId ); if( !aViewer ) @@ -154,7 +172,10 @@ void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs, } aViewPort->onBoundingRectChanged(); // specific of HYDRO module - aViewPort->fitAll(); + if ( theDoFitAll ) + { + aViewPort->fitAll(); + } } void HYDROGUI_Displayer::purgeObjects( const int theViewerId ) @@ -196,7 +217,7 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity case KIND_IMAGE: aDriver = new HYDROGUI_PrsImageDriver(); break; - case KIND_POLYLINE: + case KIND_POLYLINEXY: aDriver = new HYDROGUI_PrsPolylineDriver(); break; case KIND_ZONE: @@ -212,3 +233,128 @@ HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity return aDriver; } + +QString HYDROGUI_Displayer::GetType() const +{ + return GraphicsView_Viewer::Type(); +} + +void HYDROGUI_Displayer::SaveCursorViewPosition( SUIT_ViewWindow* theViewWindow ) +{ + myIsPositionSaved = false; + myXPosition = 0; + myYPosition = 0; + + SUIT_ViewWindow* aViewWindow = theViewWindow; + if ( !theViewWindow ) { + SUIT_ViewManager* aViewMgr = module()->getApp()->activeViewManager(); + aViewWindow = aViewMgr ? aViewMgr->getActiveView() : 0; + if ( !aViewWindow ) + return; + } + + OCCViewer_ViewWindow* anOCCViewWindow = + dynamic_cast( aViewWindow ); + if ( anOCCViewWindow ) { + // Get the selected point coordinates + OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort(); + if ( aViewPort ) { + QPoint aViewPos = aViewPort->mapFromGlobal( QCursor::pos() ); + myXPosition = aViewPos.x(); + myYPosition = aViewPos.y(); + myIsPositionSaved = true; + } + } + else { + SVTK_ViewWindow* aVTKViewWindow = + dynamic_cast(aViewWindow); + if ( aVTKViewWindow ) { + vtkRenderer* aRen = aVTKViewWindow->getRenderer(); + if ( aRen ) + { + vtkCamera* aCamera = aRen->GetActiveCamera(); + double* aNormal = aCamera->GetViewPlaneNormal(); + vtkRenderWindowInteractor* anInteractor = aVTKViewWindow->getInteractor(); + if ( anInteractor ) + { + anInteractor->GetLastEventPosition( myXPosition, myYPosition ); + myIsPositionSaved = true; + } + } + } + } + if (!myIsPositionSaved) + int aValue = 0; +} + +bool HYDROGUI_Displayer::GetCursorViewCoordinates( SUIT_ViewWindow* theViewWindow, + double& theXCoordinate, + double& theYCoordinate, + double& theZCoordinate ) +{ + theXCoordinate = 0; + theYCoordinate = 0; + theZCoordinate = 0; + bool doShow = false; + if ( !theViewWindow || !myIsPositionSaved ) + return doShow; + + OCCViewer_ViewWindow* anOCCViewWindow = + dynamic_cast(theViewWindow); + if ( anOCCViewWindow ) { + // Get the selected point coordinates + OCCViewer_ViewPort3d* aViewPort = anOCCViewWindow->getViewPort(); + if ( !aViewPort ) { + return doShow; + } + gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( myXPosition, myYPosition, + aViewPort->getView() ); + theXCoordinate = aPnt.X(); + theYCoordinate = aPnt.Y(); + doShow = true; + } + else + { + SVTK_ViewWindow* aVTKViewWindow = + dynamic_cast(theViewWindow); + if ( aVTKViewWindow ) { + vtkRenderer* aRen = aVTKViewWindow->getRenderer(); + if ( aRen ) + { + vtkCamera* aCamera = aRen->GetActiveCamera(); + double* aNormal = aCamera->GetViewPlaneNormal(); + myPicker->Pick( myXPosition, myYPosition, 0, aRen ); + double* aCoords = myPicker->GetPickPosition(); + /////////////////////// Use the same algorithm as for OCC + double X, Y, Z; + double aXp, aYp, aZp; + double Vx, Vy, Vz; + X = aCoords[0]; + Y = aCoords[1]; + Z = aCoords[2]; + Vx = aNormal[0]; + Vy = aNormal[1]; + Vz = aNormal[2]; + Standard_Real aPrec = LOCAL_SELECTION_TOLERANCE; + if ( fabs( Vz ) > aPrec ) { + double aT = -Z/Vz; + aXp = X + aT*Vx; + aYp = Y + aT*Vy; + aZp = Z + aT*Vz; + } + else { // Vz = 0 - the eyed plane is orthogonal to Z plane - XOZ, or YOZ + aXp = aYp = aZp = 0; + if ( fabs( Vy ) < aPrec ) // Vy = 0 - the YOZ plane + aYp = Y; + else if ( fabs( Vx ) < aPrec ) // Vx = 0 - the XOZ plane + aXp = X; + } + ///////////////////////// + theXCoordinate = aXp; + theYCoordinate = aYp; + doShow = true; + } + } + } + return doShow; +}