X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ZLayers.cxx;h=ac479434cafb04f231eb35d9a8c9053b4cedfd39;hb=d6e19029f8b41f295db878e9aecf451c2edda4af;hp=2e9fad629670439b417130c7e1ed28070a8ac9d0;hpb=09d10e66ba0fac5353c8d1f138055fc6fe86fb65;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ZLayers.cxx b/src/HYDROGUI/HYDROGUI_ZLayers.cxx index 2e9fad62..ac479434 100644 --- a/src/HYDROGUI/HYDROGUI_ZLayers.cxx +++ b/src/HYDROGUI/HYDROGUI_ZLayers.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,29 +21,62 @@ #include #include -class PrsMgr_PresentationManager +void SetZLayerForPrs( const Handle(PrsMgr_Presentation)& thePrs, int theLayerId ); + +void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject, + const int theMode, const int theLayerId ) { -public: - static void SetZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject, - const Standard_Integer theMode, - const Standard_Integer theLayerId ) + PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations(); + for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++) { - PrsMgr_Presentations& aPresentations = thePresentableObject->Presentations(); - for (Standard_Integer aIdx = 1; aIdx <= aPresentations.Length (); aIdx++) + Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation (); + if ( aPresentations (aIdx).Mode() == theMode ) { - Handle(PrsMgr_Presentation) aPrs = aPresentations (aIdx).Presentation (); - if ( aPresentations (aIdx).Mode() == theMode ) - aPrs->SetZLayer (theLayerId); + SetZLayerForPrs( aPrs, theLayerId ); } } -}; +} -void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject, - const int theMode, const int theLayerId ) +void SetZLayerSettings( const Handle_V3d_Viewer& theViewer3d, int theLayerId, bool theIsOrdered ) { - PrsMgr_PresentationManager::SetZLayer( thePresentableObject, theMode, theLayerId ); + if ( theViewer3d.IsNull() /*|| theLayerId < 0*/ ) + { + return; + } + + Graphic3d_ZLayerSettings aSettings = theViewer3d->ZLayerSettings( theLayerId ); + // enable depth write + aSettings.EnableSetting( Graphic3d_ZLayerDepthWrite ); + // disable depth clear + aSettings.DisableSetting( Graphic3d_ZLayerDepthClear ); + if ( theIsOrdered ) { + // disable depth test + aSettings.DisableSetting( Graphic3d_ZLayerDepthTest ); + // disable depth offset + aSettings.DisableSetting( Graphic3d_ZLayerDepthOffset ); + } else { + // enable depth test + aSettings.EnableSetting( Graphic3d_ZLayerDepthTest ); + // set depth offset + aSettings.SetDepthOffsetPositive(); + } + + // set new settings + theViewer3d->SetZLayerSettings( theLayerId, aSettings ); } +int CreateTopZLayer( const Handle_V3d_Viewer& theViewer3d ) +{ + int aTopZLayer = -1; + + if ( theViewer3d && !theViewer3d->AddZLayer( aTopZLayer ) ) { + aTopZLayer = -1; + } + + return aTopZLayer; +} + + HYDROGUI_ZLayersIterator::HYDROGUI_ZLayersIterator( const Handle_V3d_Viewer& theViewer ) : myIndex( 0 ), myNewZLayer( -1 ), myViewer( theViewer ) { @@ -73,34 +102,36 @@ void HYDROGUI_ZLayersIterator::Init( const Handle_V3d_Viewer& theViewer ) bool HYDROGUI_ZLayersIterator::More() const { - return myIndex <= (int)myZLayers.size() || myNewZLayer >= 0; + return myIndex < (int)myZLayers.size() || myNewZLayer >= 0; } void HYDROGUI_ZLayersIterator::Next() { - if( myIndex < (int)myZLayers.size() ) - myIndex++; - else if( !myViewer.IsNull() ) - { - bool isOK = myViewer->AddZLayer( myNewZLayer )==Standard_True; - if( !isOK ) - myNewZLayer = -1; + myIndex++; + + if( myIndex >= (int)myZLayers.size() && + !myViewer.IsNull() ) { + myNewZLayer = CreateTopZLayer( myViewer ); } } -int HYDROGUI_ZLayersIterator::MaxLayer() const +int HYDROGUI_ZLayersIterator::TopLayer() const { - int aMaxLayer = -1; - for( int i=0, n=myZLayers.size(); i aMaxLayer ) - aMaxLayer = myZLayers[i]; - return aMaxLayer; + int aTopLayer = -1; + + if ( myNewZLayer >= 0 ) { + aTopLayer = myNewZLayer; + } else if ( !myZLayers.empty() ) { + aTopLayer = myZLayers.back(); + } + + return aTopLayer; } int HYDROGUI_ZLayersIterator::LayerId() const { - if( More() ) + if( myIndex < (int)myZLayers.size() ) return myZLayers[myIndex]; else return myNewZLayer;