From: mzn Date: Wed, 25 Dec 2013 14:07:25 +0000 (+0000) Subject: Bug #224: Objects interpolate each other in OCC viewer. X-Git-Tag: BR_hydro_v_0_7~59 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b7337e3ea5eeb15fdad4eac991480a20405f8cff;p=modules%2Fhydro.git Bug #224: Objects interpolate each other in OCC viewer. --- diff --git a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx index 2f7074ae..2ffdc543 100644 --- a/src/HYDROGUI/HYDROGUI_ChannelOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ChannelOp.cxx @@ -236,7 +236,7 @@ void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit ) if ( !myViewManager || !myPreviewPrs ) return; - myPreviewPrs->update(); + myPreviewPrs->update( true, true ); } void HYDROGUI_ChannelOp::erasePreview() diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 4d6b818b..c8da5e4d 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -190,6 +190,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) foreach ( const int anId, anObsoleteIds ) { myViewManagerMap.remove( anId ); myObjectStateMap.remove( anId ); + myObjectDisplayOrderMap.remove( anId ); myShapesMap.remove( anId ); myVTKPrsMap.remove( anId ); } @@ -867,6 +868,13 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId, ObjectState& anObjectState = aEntry2ObjectStateMap[ anEntry ]; anObjectState.Visibility = theState; + + // Remember the display order ( needed for Z layers assignment only ) + QStringList& anObjectEntries = myObjectDisplayOrderMap[ theViewId ]; + anObjectEntries.removeAll( anEntry ); + if ( theState ) { + anObjectEntries.append( anEntry ); + } } } @@ -1517,4 +1525,19 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aX ).arg( anY ) ); } } +} + +/** + * Get the object display order. Needed for Z layers assignment only. + */ +int HYDROGUI_Module::getObjectDisplayOrder( + const int theViewId, const Handle(HYDROData_Entity)& theObject) const +{ + if( theObject.IsNull() ) + return -1; + + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theObject ); + QStringList anObjectEntries = myObjectDisplayOrderMap.value( theViewId ); + + return anObjectEntries.indexOf( anEntry ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index a51ef9d2..58583ab5 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -171,6 +171,9 @@ public: */ virtual bool renameObject( const QString& theEntry, const QString& theName ); + int getObjectDisplayOrder( const int theViewId, + const Handle(HYDROData_Entity)& theObject ) const; + protected: CAM_DataModel* createDataModel(); @@ -236,7 +239,9 @@ private: HYDROGUI_VTKPrsDisplayer* myVTKDisplayer; ViewManagerMap myViewManagerMap; - ViewId2Entry2ObjectStateMap myObjectStateMap; + ViewId2Entry2ObjectStateMap myObjectStateMap; + + QMap myObjectDisplayOrderMap; ViewId2ListOfShapes myShapesMap; ViewId2ListOfVTKPrs myVTKPrsMap; diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index 39810702..3dbe862c 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -31,6 +31,8 @@ #include #include +#include + #include #include #include @@ -122,9 +124,33 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, if( aCtx.IsNull() ) return; - for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) - { + // Sort objects by display order ( needed for Z layers assignment only ) + HYDROData_SequenceOfObjects anObjects; + int aMaxIndex = -1; + for ( int i = 1, n = theObjs.Length(); i <= n; i++ ) { Handle(HYDROData_Entity) anObj = theObjs.Value( i ); + if ( anObj.IsNull() || anObj->IsRemoved() ) { + continue; + } + + int aDisplayOrderIndex = module()->getObjectDisplayOrder( (size_t)aViewer, anObj ); + if ( aDisplayOrderIndex > aMaxIndex ) { + anObjects.Append( anObj ); + aMaxIndex = aDisplayOrderIndex; + } else { + anObjects.Prepend( anObj ); + } + } + + // Get existing Z layers + TColStd_SequenceOfInteger anExistingZLayers; + aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers ); + int aNbLayers = anExistingZLayers.Length(); + + // Display + for ( int i = 1, n = anObjects.Length(); i <= n; i++ ) + { + Handle(HYDROData_Entity) anObj = anObjects.Value( i ); if ( anObj.IsNull() || anObj->IsRemoved() ) continue; @@ -143,6 +169,20 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, { bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj ); anObjShape->setVisible( anIsVisible, false ); + + // Set Z layer + Standard_Integer aLayerId = -1; + if ( i <= aNbLayers ) { + aLayerId = anExistingZLayers.Value( i ); + } else { + Standard_Integer aNewId = -1; + if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) { + aLayerId = aNewId; + } + } + if ( aLayerId >= 0 ) { + aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId ); + } } } diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index 37eaf350..ca88fc01 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -28,6 +28,8 @@ #include #include +#include + #include #include #include @@ -110,7 +112,8 @@ void HYDROGUI_Shape::erase( const bool theIsUpdateViewer ) myContext->Erase( myShape, theIsUpdateViewer ); } -void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) +void HYDROGUI_Shape::update( const bool theIsUpdateViewer, + const bool theIsDisplayOnTop ) { setIsToUpdate( false ); @@ -379,6 +382,17 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) return; myContext->Display( myShape, theIsUpdateViewer ); + + if ( theIsDisplayOnTop ) { + // Display the shape on the top Z layer + Standard_Integer aNewLayerId = -1; + if ( myContext->CurrentViewer() && + myContext->CurrentViewer()->AddZLayer( aNewLayerId ) && + aNewLayerId > 0 ) { + myContext->SetZLayer( myShape, aNewLayerId ); + } + } + if (isDeactivateSelection) myContext->Deactivate(myShape); } diff --git a/src/HYDROGUI/HYDROGUI_Shape.h b/src/HYDROGUI/HYDROGUI_Shape.h index a1af4dbb..b16161ce 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.h +++ b/src/HYDROGUI/HYDROGUI_Shape.h @@ -51,7 +51,8 @@ public: Handle(HYDROData_Entity) getObject() const { return myObject; } - virtual void update( const bool theIsUpdateViewer = true ); + virtual void update( const bool theIsUpdateViewer = true, + const bool theIsDisplayOnTop = false ); virtual bool getIsToUpdate() const { return myIsToUpdate; } virtual void setIsToUpdate( bool theState ) { myIsToUpdate = theState; } @@ -98,6 +99,8 @@ public: const bool theIsUpdateViewer = true ); virtual QString getTextureFileName() const; + virtual Handle(AIS_Shape) getAISShape() const { return myShape; } + protected: virtual void buildShape(); virtual void updateShape( const bool theToDisplay = true, diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 06f07cfc..66178e7d 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -221,7 +221,7 @@ void HYDROGUI_StreamOp::createPreview() } if ( myPreviewPrs ) { - myPreviewPrs->update(); + myPreviewPrs->update( true, true ); } }