X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVTKViewer%2FVTKViewer_ViewFrame.cxx;h=3fa967e2a0d4b67153d98700989e82f08bede3fb;hb=18251ce9c72dbdec318e37a355adfe4fc5869e7f;hp=1dc5b8db490bd521e1721652a1ca718896c9fb5b;hpb=ca921d4a4fa66c9dfe515a6f31bee1817601dfb9;p=modules%2Fkernel.git diff --git a/src/VTKViewer/VTKViewer_ViewFrame.cxx b/src/VTKViewer/VTKViewer_ViewFrame.cxx index 1dc5b8db4..3fa967e2a 100644 --- a/src/VTKViewer/VTKViewer_ViewFrame.cxx +++ b/src/VTKViewer/VTKViewer_ViewFrame.cxx @@ -29,6 +29,7 @@ #include "VTKViewer_ViewFrame.h" #include "VTKViewer_Utilities.h" #include "VTKViewer_Trihedron.h" +#include "SALOME_CubeAxesActor2D.h" #include "VTKViewer_RenderWindow.h" #include "VTKViewer_RenderWindowInteractor.h" #include "VTKViewer_InteractorStyleSALOME.h" @@ -65,9 +66,16 @@ #include #include #include +#include #include +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + using namespace std; /*! @@ -79,11 +87,13 @@ VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name) m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1; m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1; m_Triedron = VTKViewer_Trihedron::New(); + m_CubeAxes = SALOME_CubeAxesActor2D::New(); m_Transform = SALOME_Transform::New(); //m_Renderer = VTKViewer_Renderer::New() ; m_Renderer = vtkRenderer::New() ; m_Triedron->AddToRender(m_Renderer); + m_Renderer->AddProp(m_CubeAxes); InitialSetup(); } @@ -118,11 +128,31 @@ void VTKViewer_ViewFrame::InitialSetup() { m_RWInteractor->Initialize(); m_RWInteractor->setViewFrame(this); - RWS->setTriedron(m_Triedron); + RWS->setViewFrame(this); //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle RWS->FindPokedRenderer(0, 0); + vtkTextProperty* tprop = vtkTextProperty::New(); + tprop->SetColor(1, 1, 1); + tprop->ShadowOn(); + + float bnd[6]; + bnd[0] = bnd[2] = bnd[4] = 0; + bnd[1] = bnd[3] = bnd[5] = m_Triedron->GetSize(); + m_CubeAxes->SetLabelFormat("%6.4g"); + m_CubeAxes->SetBounds(bnd); + m_CubeAxes->SetCamera(m_Renderer->GetActiveCamera()); + m_CubeAxes->SetLabelFormat("%6.4g"); + m_CubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee + m_CubeAxes->SetFontFactor(0.8); + m_CubeAxes->SetAxisTitleTextProperty(tprop); + m_CubeAxes->SetAxisLabelTextProperty(tprop); + m_CubeAxes->SetCornerOffset(0.0); + m_CubeAxes->SetScaling(0); + m_CubeAxes->SetNumberOfLabels(5); + tprop->Delete(); + setCentralWidget( m_RW ); onViewReset(); } @@ -139,6 +169,8 @@ VTKViewer_ViewFrame::~VTKViewer_ViewFrame() { m_Renderer->RemoveAllProps(); // NRI : BugID 1137: m_Renderer->Delete() ; m_Triedron->Delete(); + + m_CubeAxes->Delete(); INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()"); } @@ -153,44 +185,8 @@ bool VTKViewer_ViewFrame::isTrihedronDisplayed(){ return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn; } -bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize ) -{ - // calculating diagonal of visible props of the renderer - float bnd[ 6 ]; - m_Triedron->VisibilityOff(); - if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 ) - { - bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100; - bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0; - } - m_Triedron->VisibilityOn(); - float aLength = 0; - static bool CalcByDiag = false; - if ( CalcByDiag ) - { - aLength = sqrt( ( bnd[1]-bnd[0])*(bnd[1]-bnd[0] )+ - ( bnd[3]-bnd[2])*(bnd[3]-bnd[2] )+ - ( bnd[5]-bnd[4])*(bnd[5]-bnd[4] ) ); - } - else - { - aLength = bnd[ 1 ]-bnd[ 0 ]; - aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength ); - aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength ); - } - - static float aSizeInPercents = 105; - QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" ); - if ( !aSetting.isEmpty() ) - aSizeInPercents = aSetting.toFloat(); - - static float EPS_SIZE = 5.0E-3; - theSize = m_Triedron->GetSize(); - theNewSize = aLength * aSizeInPercents / 100.0; - - // if the new trihedron size have sufficient difference, then apply the value - return fabs( theNewSize - theSize) > theSize * EPS_SIZE || - fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE; +bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){ + return m_CubeAxes->GetVisibility() == 1; } double VTKViewer_ViewFrame::GetTrihedronSize() const @@ -198,17 +194,41 @@ double VTKViewer_ViewFrame::GetTrihedronSize() const return m_Triedron->GetSize(); } -void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate ) +void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced) { - if ( !isTrihedronDisplayed() && !forcedUpdate ) + + if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced) return; + float bnd[ 6 ]; + float newbnd[6]; + newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT; + newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT; + + m_CubeAxes->GetBounds(bnd); + if(MYDEBUG) + cout << "Bounds: BEFORE\n" + << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n" + << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n" + << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n"; + int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer ); - if ( aVisibleNum || forcedUpdate ) + if ( aVisibleNum ) { // if the new trihedron size have sufficient difference, then apply the value - double aNewSize = 100, anOldSize; - if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate ) + double aNewSize = 100, anOldSize=m_Triedron->GetSize(); + + m_Triedron->VisibilityOff(); + m_CubeAxes->VisibilityOff(); + static float aSizeInPercents = 105; + QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" ); + if ( !aSetting.isEmpty() ) + aSizeInPercents = aSetting.toFloat(); + bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents); + m_Triedron->VisibilityOn(); + m_CubeAxes->VisibilityOn(); + + if ( isComputeTrihedronSize ) { m_Triedron->SetSize( aNewSize ); // itearte throuh displayed objects and set size if necessary @@ -221,32 +241,72 @@ void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate ) { if ( aSActor->IsResizable() ) aSActor->SetSize( 0.5 * aNewSize ); + if( aSActor->GetVisibility()){ + float abounds[6]; + aSActor->GetBounds(abounds); + if(MYDEBUG) + cout << "Bounds: Actor="< -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT && + abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT && + abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT) + for(int i=0;i<5;i=i+2){ + if(abounds[i]newbnd[i+1]) newbnd[i+1]=abounds[i+1]; + + } + } } } } } + if( newbnd[0]-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){ + for(int i=0;i<6;i++) bnd[i] = newbnd[i]; + m_CubeAxes->SetBounds(bnd); + } + if(MYDEBUG) + cout << "Bounds AFTER: VisibleActors="<SetBounds(bnd); ::ResetCameraClippingRange(m_Renderer); } void VTKViewer_ViewFrame::onAdjustTrihedron() +{ + AdjustTrihedrons(false); +} + +void VTKViewer_ViewFrame::onAdjustCubeAxes() { - AdjustTrihedrons( false ); + AdjustTrihedrons(false); } /*! Display/hide Trihedron */ void VTKViewer_ViewFrame::onViewTrihedron(){ + onViewCubeAxes(); if(!m_Triedron) return; - if(isTrihedronDisplayed()) - m_Triedron->VisibilityOff(); - else{ - m_Triedron->VisibilityOn(); - } + if(isTrihedronDisplayed()) m_Triedron->VisibilityOff(); + else m_Triedron->VisibilityOn(); + Repaint(); +} + +void VTKViewer_ViewFrame::onViewCubeAxes(){ + if(!m_CubeAxes) return; + if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff(); + else m_CubeAxes->VisibilityOn(); Repaint(); } + /*! Provides top projection of the active view */ @@ -317,7 +377,33 @@ void VTKViewer_ViewFrame::onViewFront(){ Fits all objects in the active view */ void VTKViewer_ViewFrame::onViewFitAll(){ - m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll(); + + int aTriedronWasVisible = false; + int aCubeAxesWasVisible = false; + if(m_Triedron){ + aTriedronWasVisible = isTrihedronDisplayed(); + if(aTriedronWasVisible) m_Triedron->VisibilityOff(); + } + if(m_CubeAxes){ + aCubeAxesWasVisible = isCubeAxesDisplayed(); + if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff(); + } + + if(m_Triedron->GetVisibleActorCount(m_Renderer)){ + m_Triedron->VisibilityOff(); + m_CubeAxes->VisibilityOff(); + ::ResetCamera(m_Renderer); + }else{ + m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); + m_CubeAxes->SetVisibility(2); + ::ResetCamera(m_Renderer,true); + } + if(aTriedronWasVisible) m_Triedron->VisibilityOn(); + else m_Triedron->VisibilityOff(); + if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn(); + else m_CubeAxes->VisibilityOff(); + ::ResetCameraClippingRange(m_Renderer); + Repaint(); } @@ -326,14 +412,23 @@ void VTKViewer_ViewFrame::onViewFitAll(){ */ void VTKViewer_ViewFrame::onViewReset(){ int aTriedronIsVisible = isTrihedronDisplayed(); + int aCubeAxesIsVisible = isCubeAxesDisplayed(); + m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); + m_CubeAxes->SetVisibility(0); + ::ResetCamera(m_Renderer,true); vtkCamera* aCamera = m_Renderer->GetActiveCamera(); aCamera->SetPosition(1,-1,1); aCamera->SetViewUp(0,0,1); ::ResetCamera(m_Renderer,true); + if(aTriedronIsVisible) m_Triedron->VisibilityOn(); else m_Triedron->VisibilityOff(); + + if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn(); + else m_CubeAxes->VisibilityOff(); + static float aCoeff = 3.0; aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); Repaint(); @@ -603,6 +698,7 @@ void VTKViewer_ViewFrame::EraseAll() void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron) { if (theUpdateTrihedron) onAdjustTrihedron(); + //if (theUpdateCubeAxes) onAdjustCubeAxes(); m_RW->update(); } @@ -811,15 +907,17 @@ void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theTo if ( aComponent->_is_nil() ) return; - bool isTrhDisplayed = isTrihedronDisplayed(); - m_RWInteractor->RemoveAll( false ); //m_RWInteractor->EraseAll(); aSel->ClearIObjects(); - + + /* + // ENK commented, already added to renderer in + // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...) if ( isTrhDisplayed ) - m_Triedron->AddToRender( m_Renderer ); + m_Triedron->AddToRender( m_Renderer ); + */ std::list aList; SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList ); @@ -841,17 +939,94 @@ void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theTo Repaint(); } +#define INCREMENT_FOR_OP 10 +//======================================================================= +// name : onPanLeft +// Purpose : Performs incremental panning to the left +//======================================================================= +void VTKViewer_ViewFrame::onPanLeft() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 ); +} +//======================================================================= +// name : onPanRight +// Purpose : Performs incremental panning to the right +//======================================================================= +void VTKViewer_ViewFrame::onPanRight() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 ); +} +//======================================================================= +// name : onPanUp +// Purpose : Performs incremental panning to the top +//======================================================================= +void VTKViewer_ViewFrame::onPanUp() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP ); +} +//======================================================================= +// name : onPanDown +// Purpose : Performs incremental panning to the bottom +//======================================================================= +void VTKViewer_ViewFrame::onPanDown() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP ); +} +//======================================================================= +// name : onZoomIn +// Purpose : Performs incremental zooming in +//======================================================================= +void VTKViewer_ViewFrame::onZoomIn() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP ); +} +//======================================================================= +// name : onZoomOut +// Purpose : Performs incremental zooming out +//======================================================================= +void VTKViewer_ViewFrame::onZoomOut() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP ); +} +//======================================================================= +// name : onRotateLeft +// Purpose : Performs incremental rotating to the left +//======================================================================= +void VTKViewer_ViewFrame::onRotateLeft() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); +} +//======================================================================= +// name : onRotateRight +// Purpose : Performs incremental rotating to the right +//======================================================================= +void VTKViewer_ViewFrame::onRotateRight() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 ); +} +//======================================================================= +// name : onRotateUp +// Purpose : Performs incremental rotating to the top +//======================================================================= +void VTKViewer_ViewFrame::onRotateUp() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP ); +} - - - - +//======================================================================= +// name : onRotateDown +// Purpose : Performs incremental rotating to the bottom +//======================================================================= +void VTKViewer_ViewFrame::onRotateDown() +{ + m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP ); +}