// 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<Handle(HYDROData_Entity), bool> Object2ApplyZLayer;
+ QList<Object2ApplyZLayer> 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;
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;
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<HYDROGUI_Operation*>( 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 ) ) {