}
}
-int HYDROGUI_OCCDisplayer::AddTopZLayer( OCCViewer_ViewManager* theMgr )
+int HYDROGUI_OCCDisplayer::AddPreviewZLayer( OCCViewer_ViewManager* theMgr )
{
int aLayer = -1;
OCCViewer_Viewer* aViewer = theMgr->getOCCViewer();
if ( !aViewer )
return aLayer;
- Standard_Integer aNewId = -1;
- if ( aViewer->getViewer3d()->AddZLayer( aNewId ) )
- aLayer = aNewId;
+ aLayer = CreateTopZLayer( aViewer->getViewer3d() );
+
+ // Hilight presentation should be on top
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if( !aCtx.IsNull() ) {
+ int aTopLayer = CreateTopZLayer( aViewer->getViewer3d() );
+ if ( aTopLayer > 0 ) {
+ UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, aTopLayer );
+ }
+ }
return aLayer;
}
// Get 3d viewer
Handle(V3d_Viewer) aViewer3d = aViewer->getViewer3d();
- // Get existing Z layers
- TColStd_SequenceOfInteger anExistingZLayers;
- aViewer3d->GetAllZLayers( anExistingZLayers );
- int aNbLayers = anExistingZLayers.Length();
-
- // Display objects
- int aNextZLayerIndex = 2; // don't use the first default Z layer ( which index = 1 )
+ // Display objects:
+ HYDROGUI_ZLayersIterator aZLayersIt( aViewer->getViewer3d() );
+ if ( !aZLayersIt.More() ) {
+ aZLayersIt.Next();
+ }
// 1. Display the ordered objects:
HYDROData_SequenceOfObjects::Iterator anOrderedIter( anOrderedToDisplay );
for ( ; anOrderedIter.More(); anOrderedIter.Next() ) {
Handle(HYDROData_Entity) anObj = anOrderedIter.Value();
- if ( Display( anObj, aViewer, theIsForced, aNextZLayerIndex, true ) ) {
- aNextZLayerIndex++;
+ if ( Display( anObj, aViewer, theIsForced ) ) {
+ // set Z layer ( one Z layer for each ordered object )
+ int aZLayerId = aZLayersIt.LayerId();
+ SetZLayer( aViewer, anObj, aZLayerId );
+ SetZLayerSettings( aViewer3d, aZLayerId, true );
+ aZLayersIt.Next();
}
}
// 2. Display the unordered objects:
bool isDisplayed = false;
+ int anUnorderedZLayerId = aZLayersIt.LayerId();
HYDROData_SequenceOfObjects::Iterator anUnorderedIter( anUnorderedToDisplay );
for ( ; anUnorderedIter.More(); anUnorderedIter.Next() ) {
Handle(HYDROData_Entity) anObj = anUnorderedIter.Value();
- if ( Display( anObj, aViewer, theIsForced, aNextZLayerIndex, false ) ) {
+ if ( Display( anObj, aViewer, theIsForced) ) {
+ // set Z layer ( one Z layer for all unordered objects )
+ SetZLayer( aViewer, anObj, anUnorderedZLayerId );
+ if ( !isDisplayed ) {
+ SetZLayerSettings( aViewer3d, anUnorderedZLayerId, false );
+ }
isDisplayed = true;
}
}
// 3. Update the top Z layer index
if ( isDisplayed ) {
- aNextZLayerIndex++;
+ aZLayersIt.Next();
}
// Update Z layer of the active operation
- aViewer3d->GetAllZLayers( anExistingZLayers );
+ int aPreviewZLayerId = aZLayersIt.LayerId();
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 ( aNextZLayerIndex <= aNbLayers )
- aLayerId = anExistingZLayers.Value( aNextZLayerIndex );
- else {
- Standard_Integer aNewId = -1;
- if ( aViewer->getViewer3d()->AddZLayer( aNewId ) ) {
- aLayerId = aNewId;
- }
- }
- aHOp->updatePreviewZLayer( aLayerId );
+ aHOp->updatePreviewZLayer( aPreviewZLayerId );
+ aZLayersIt.Next();
}
- HYDROGUI_ZLayersIterator anIt( aViewer->getViewer3d() );
- int aMaxLayer = anIt.MaxLayer();
- UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, aMaxLayer );
+ // Update Z layer of hilight presentations
+ int aHilightLayer = aZLayersIt.TopLayer();
+ UpdateZLayersOfHilightPresentationsOfDisplayedObjects( aCtx, aHilightLayer );
- if ( theDoFitAll )
- {
+ // Fit all / update selection
+ if ( theDoFitAll ) {
OCCViewer_ViewManager* aViewManager
= ::qobject_cast<OCCViewer_ViewManager*>( aViewer->getViewManager() );
- if ( aViewManager )
- {
+ if ( aViewManager ) {
OCCViewer_ViewWindow* aViewWindow =
::qobject_cast<OCCViewer_ViewWindow*>( aViewManager->getActiveView() );
- if ( aViewWindow )
- {
+ if ( aViewWindow ) {
aViewWindow->onFitAll();
}
}
- }
- else if ( !aCtx.IsNull() ) // TODO: determine if this code is necessary (added as a fix for issue# 359)
- {
+ }
+ else if ( !aCtx.IsNull() ) { // TODO: determine if this code is necessary (added as a fix for issue# 359)
aCtx->UpdateSelected();
}
}
bool HYDROGUI_OCCDisplayer::Display( const Handle(HYDROData_Entity)& theObject,
const OCCViewer_Viewer* theViewer,
- const bool theIsForced,
- const int theZLayerIndex,
- const bool theIsOrdered )
+ const bool theIsForced )
{
bool aRes = false;
bool anIsVisible = module()->isObjectVisible( aViewerId, theObject );
anObjShape->setVisible( anIsVisible, false );
- // Set Z layer
- Handle(V3d_Viewer) aViewer3d = theViewer->getViewer3d();
- if ( !aViewer3d.IsNull() ) {
- // Get existing layers
- TColStd_SequenceOfInteger anExistingZLayers;
- aViewer3d->GetAllZLayers( anExistingZLayers );
- int aNbLayers = anExistingZLayers.Length();
-
- // Get or create the appropriate layer
- Standard_Integer aLayerId = -1;
- if ( theZLayerIndex <= aNbLayers ) {
- aLayerId = anExistingZLayers.Value( theZLayerIndex );
- } else {
- Standard_Integer aNewId = -1;
- if ( aViewer3d->AddZLayer( aNewId ) ) {
- aLayerId = aNewId;
- }
- }
-
- if ( aLayerId >= 0 ) {
- // set Z layer
- aCtx->SetZLayer( anObjShape->getAISShape(), aLayerId );
-
- // set Z layer settings for the 3d viewer:
- // current settings
- Graphic3d_ZLayerSettings aSettings = aViewer3d->ZLayerSettings( aLayerId );
- // 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
- aViewer3d->SetZLayerSettings( aLayerId, aSettings );
-
- aRes = true;
- }
- }
+ aRes = true;
}
return aRes;
+}
+
+void HYDROGUI_OCCDisplayer::SetZLayer( const OCCViewer_Viewer* theViewer,
+ const Handle(HYDROData_Entity)& theObject,
+ const int theZLayerId )
+{
+ if ( !theViewer || ( theZLayerId < 0 ) ) {
+ return;
+ }
+
+ // Get interactive context
+ Handle(AIS_InteractiveContext) aCtx = theViewer->getAISContext();
+ if( aCtx.IsNull() ) {
+ return;
+ }
+
+ // Get viewer id
+ size_t aViewerId = (size_t)theViewer;
+
+ // Get object shape
+ HYDROGUI_Shape* anObjShape = module()->getObjectShape( aViewerId, theObject );
+
+ // Set Z layer
+ if ( anObjShape ) {
+ aCtx->SetZLayer( anObjShape->getAISShape(), theZLayerId );
+ }
}
\ No newline at end of file
virtual QString GetType() const;
/**
- * \brief Add the top z layer and returns its index.
+ * \brief Add the z layer for preview and returns its index.
* \param theMgr OCC view manager
*/
- int AddTopZLayer( OCCViewer_ViewManager* theMgr );
+ int AddPreviewZLayer( OCCViewer_ViewManager* theMgr );
/**
* \brief Removes the z layer.
/**
* \brief Creates new OCC shape.
* \param theViewerId viewer identifier
- * \param theContext context of OCC viwer
+ * \param theContext context of OCC viewer
* \param theObject data model object
* \return pointer to new created shape
*/
* \param theObject the object to display
* \param theViewer the viewer for displaying
* \param theIsForced the flag used to update the object shape
- * \param theZLayerIndex the Z layer index
- * \param theIsOrdered the flag indicating if the Z layer ordering available for the object
* \return true in case of success
*/
bool Display( const Handle(HYDROData_Entity)& theObject,
const OCCViewer_Viewer* theViewer,
- const bool theIsForced,
- const int theZLayerIndex,
- const bool theIsOrdered );
+ const bool theIsForced );
+
+ /**
+ * \brief Set Z layer to the shape corresponding to the HYDRO data object.
+ * \param theViewer the viewer for Z layer setting
+ * \param theObject the HYDRO object
+ * \param theZLayerId the Z layer ID
+ */
+ void SetZLayer( const OCCViewer_Viewer* theViewer,
+ const Handle(HYDROData_Entity)& theObject,
+ const int theZLayerId );
};
#endif
*/
void HYDROGUI_Operation::setPreviewManager( OCCViewer_ViewManager* theManager )
{
- if ( !theManager && myPreviewManager )
- module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
+ //No good: preview Z layer could be used by usual presentations
+ //if ( !theManager && myPreviewManager )
+ // module()->getOCCDisplayer()->RemoveZLayer( myPreviewManager, getPreviewZLayer() );
myPreviewManager = theManager;
if ( myPreviewManager )
- setPreviewZLayer( module()->getOCCDisplayer()->AddTopZLayer( myPreviewManager ) );
+ setPreviewZLayer( module()->getOCCDisplayer()->AddPreviewZLayer( myPreviewManager ) );
}
void HYDROGUI_Operation::startOperation()
setWire( aPolylineWire, false, false );
} else {
myTopoShape = aPolylineShape;
- myDisplayMode = AIS_WireFrame;
+ // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
+ // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
+ myDisplayMode = AIS_Shaded;
buildShape();
updateShape( false, false );
setWire( aPolylineWire, false, false );
} else {
myTopoShape = aPolylineShape;
- myDisplayMode = AIS_WireFrame;
+ // Set shading mode to avoid that hilight presentation is equal to "normal" object presentation.
+ // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
+ myDisplayMode = AIS_Shaded;
buildShape();
updateShape( false, false );
const bool theIsUpdateViewer )
{
myTopoShape = theWire;
- myDisplayMode = AIS_WireFrame;
+ // To avoid that hilight presentation is equal to "normal" object presentation.
+ // Note that hilight presentation is always to be on top ( i.e. in the top Z layer ).
+ myDisplayMode = AIS_Shaded;
buildShape();
updateShape( theToDisplay, theIsUpdateViewer );
getQuantityColorVal( theColor.green() ),
getQuantityColorVal( theColor.blue() ),
Quantity_TOC_RGB );
- if ( myDisplayMode == AIS_Shaded )
+
+
+ if ( myTopoShape.ShapeType() == TopAbs_WIRE ) // Note that we display polylines in shaded mode
+ {
+ myShape->SetColor( aBorderColor );
+ } else if ( myDisplayMode == AIS_Shaded )
{
if ( theColor.alpha() == 0 )
{
PrsMgr_PresentationManager::SetZLayer( thePresentableObject, theMode, theLayerId );
}
+void SetZLayerSettings( const Handle_V3d_Viewer& theViewer3d, int theLayerId, bool theIsOrdered )
+{
+ 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 )
{
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<n; i++ )
- if( myZLayers[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;
bool More() const;
void Next();
int LayerId() const;
- int MaxLayer() const;
+ int TopLayer() const;
private:
std::vector<int> myZLayers;
void SetPrsZLayer( const Handle_PrsMgr_PresentableObject& thePresentableObject,
const int theMode, const int theLayerId );
void UpdateZLayersOfHilightPresentationsOfDisplayedObjects( const Handle_AIS_InteractiveContext&, int theLayer );
+void SetZLayerSettings( const Handle_V3d_Viewer&, int theLayerId, bool theIsOrdered );
+int CreateTopZLayer( const Handle_V3d_Viewer& );
#endif
if( !aPrsObj.IsNull() )
{
theContext->MainPrsMgr()->Color( aPrsObj );
- int aMode = 0;//aPrsObj->HilightMode();
+ int aMode = aPrsObj->HasHilightMode() ? aPrsObj->HilightMode() : 0;
SetPrsZLayer( aPrsObj, aMode, theLayer );
theContext->MainPrsMgr()->Unhighlight( aPrsObj, aMode );
}