From: mzn Date: Wed, 26 Mar 2014 14:08:38 +0000 (+0000) Subject: Fix bug: objects which has no 2D prs are not displayed. X-Git-Tag: BR_hydro_v1_0_1~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e0ab858db4d12245d472c02598a9b03960fe4535;p=modules%2Fhydro.git Fix bug: objects which has no 2D prs are not displayed. --- diff --git a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx index d373be03..ee57bf97 100644 --- a/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx +++ b/src/HYDROGUI/HYDROGUI_OCCDisplayer.cxx @@ -170,25 +170,33 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, // Assign Z layer indexes aDoc->Show( theObjs ); - // TODO: implement sorting in another way + // TODO: to optimize // Sort objects by display order ( needed for Z layers assignment only ) - HYDROData_SequenceOfObjects anObjects = theObjs; - HYDROData_SequenceOfObjects anOrderedToDisplay; - HYDROData_SequenceOfObjects anAllOrdered = aDoc->GetObjectsLayerOrder(); - for ( int i = 1, n = anAllOrdered.Length(); i <= n; i++ ) { - QString anAllEntry = HYDROGUI_DataObject::dataObjectEntry( anAllOrdered.Value( i ) ); - - for ( int j = 1; j <= anObjects.Length(); j++ ) { - Handle(HYDROData_Entity) anObj = anObjects.Value( j ); - QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObj ); - if ( anEntry != anAllEntry ) { - continue; + typedef QPair Object2ApplyZLayer; + QList anOrderedToDisplay; // list of (object, is_z_layer_applicable) + HYDROData_SequenceOfObjects anObjectsToDisplay = theObjs; + HYDROData_SequenceOfObjects anOrderedObjects = aDoc->GetObjectsLayerOrder(); + + HYDROData_SequenceOfObjects::Iterator anOrderedIter( anOrderedObjects ); + for ( ; anOrderedIter.More(); anOrderedIter.Next() ) { + QString anOrderedEntry = HYDROGUI_DataObject::dataObjectEntry( anOrderedIter.Value() ); + + HYDROData_SequenceOfObjects::Iterator aToDisplayIter( anObjectsToDisplay ); + for ( ; aToDisplayIter.More(); aToDisplayIter.Next() ) { + Handle(HYDROData_Entity) anObjToDisplay = aToDisplayIter.Value(); + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( anObjToDisplay ); + if ( anEntry == anOrderedEntry ) { + anObjectsToDisplay.Remove( aToDisplayIter ); + anOrderedToDisplay.prepend( Object2ApplyZLayer( anObjToDisplay, true ) ); + break; } - anObjects.Remove( j ); - anOrderedToDisplay.Prepend( anObj ); - break; } } + // For the rest objects Z layer can't be applied + HYDROData_SequenceOfObjects::Iterator aRestObjsIter( anObjectsToDisplay ); + for ( ; aRestObjsIter.More(); aRestObjsIter.Next() ) { + anOrderedToDisplay.prepend( Object2ApplyZLayer( aRestObjsIter.Value(), false ) ); + } // Get existing Z layers TColStd_SequenceOfInteger anExistingZLayers; @@ -196,10 +204,9 @@ void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs, int aNbLayers = anExistingZLayers.Length(); // Display - int i = 1; - for ( int n = anOrderedToDisplay.Length(); i <= n; i++ ) - { - Handle(HYDROData_Entity) anObj = anOrderedToDisplay.Value( i ); + int aNextZLayerIndex = 2; // don't use the first default Z layer ( which index = 1 ) + foreach ( const Object2ApplyZLayer& aPair, anOrderedToDisplay ) { + Handle(HYDROData_Entity) anObj = aPair.first; if ( anObj.IsNull() || anObj->IsRemoved() ) continue; @@ -219,29 +226,35 @@ 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; + bool isZLayerApplicable = aPair.second; + + // set Z layer if applicable + if ( isZLayerApplicable ) { + Standard_Integer aLayerId = -1; + if ( aNextZLayerIndex <= aNbLayers ) { + aLayerId = anExistingZLayers.Value( aNextZLayerIndex ); + } else { + Standard_Integer aNewId = -1; + if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) { + aLayerId = aNewId; + } } - } - if ( aLayerId >= 0 ) { - aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId ); + if ( aLayerId >= 0 ) { + aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId ); + } + aNextZLayerIndex++; } } } - // update Z layer of the active operation + + // Update Z layer of the active operation HYDROGUI_Module* aModule = module(); SUIT_Operation* anOp = aModule->activeOperation(); HYDROGUI_Operation* aHOp = anOp ? dynamic_cast( anOp ) : 0; if ( aHOp && aHOp->getPreviewZLayer() >= 0 ) { Standard_Integer aLayerId = -1; - if ( i <= aNbLayers ) - aLayerId = anExistingZLayers.Value( i ); + if ( aNextZLayerIndex <= aNbLayers ) + aLayerId = anExistingZLayers.Value( aNextZLayerIndex ); else { Standard_Integer aNewId = -1; if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) {