// Define eye icon and empty icon
myEmpty = QPixmap( 16, 16 );
- myEmpty.fill( Qt::white );
+ myEmpty.fill( Qt::transparent );
if ( aResMgr ) {
myEye = aResMgr->loadPixmap( "HYDRO", tr( "EYE_ICO" ) );
} else {
/**
*/
QVariant HYDROGUI_ListModel::headerData( int theSection,
- Qt::Orientation theOrientation,
- int theRole ) const
+ Qt::Orientation theOrientation,
+ int theRole ) const
{
if( theOrientation==Qt::Horizontal && theRole==Qt::DisplayRole )
{
QByteArray anEncodedData;
QDataStream aStream( &anEncodedData, QIODevice::WriteOnly );
- QList<int> anIdsList = getIds( theIndexes );
+ QList<int> anIdsList = getIds( theIndexes, true );
foreach( int anId, anIdsList )
aStream << anId;
/**
*/
bool HYDROGUI_ListModel::dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
- int theRow, int theColumn, const QModelIndex& theParent )
+ int theRow, int theColumn, const QModelIndex& theParent )
{
if( theAction == Qt::IgnoreAction)
return true;
if( theColumn > 0 )
return false;
- int aDropItemId = theParent.row();
+ // TODO: to disable drop between items use: int aDropItemId = theParent.row();
+ int aDropItemId = theParent.isValid() ? theParent.row() : theRow;
QByteArray anEncodedData = theData->data( OBJ_LIST_MIME_TYPE );
QDataStream aStream( &anEncodedData, QIODevice::ReadOnly );
aStream >> anId;
anIdsList << anId;
}
- qSort( anIdsList ); // TODO should be moved?
+
move( anIdsList, DragAndDrop, false, aDropItemId ); //TODO set visibility?
return true;
}
@param theIsToSort defines if the list of ids should be sorted in ascending order
@return the list of ids
*/
-QList<int> HYDROGUI_ListModel::getIds( const QModelIndexList& theIndexes, bool theIsToSort ) const
+QList<int> HYDROGUI_ListModel::getIds( const QModelIndexList& theIndexes,
+ bool theIsToSort ) const
{
QList<int> anIds;
foreach( const QModelIndex& anIndex, theIndexes ) {
@return true in case of success
*/
bool HYDROGUI_ListModel::move( const int theItem, const OpType theType,
- bool theIsVisibleOnly, const int theDropItem )
+ bool theIsVisibleOnly, const int theDropItem )
{
bool aRes = false;
if ( theItem < 0 || theItem >= myObjects.count() ) {
@return true in case of success
*/
bool HYDROGUI_ListModel::move( const QList<int>& theItems, const OpType theType,
- bool theIsVisibleOnly, const int theDropItem )
+ bool theIsVisibleOnly, const int theDropItem )
{
bool aRes = true;
@return true if drag and drop allowed
*/
bool HYDROGUI_ListModel::isDragAndDropAllowed( const QList<int>& theItems,
- const int theDropItem ) const
+ const int theDropItem ) const
{
bool isAllowed = false;
- if ( theDropItem >= 0 && theDropItem < myObjects.count() &&
+ if ( theDropItem >= 0 &&
+ // TODO: to disable drop between items use: theDropItem < myObjects.count()
+ theDropItem <= myObjects.count() &&
!theItems.empty() && theItems.count() < myObjects.count() &&
!theItems.contains( theDropItem )) {
isAllowed = true;
const bool theIsForced,
const bool theDoFitAll )
{
+ // Get OCC viewer by id
OCCViewer_Viewer* aViewer = module()->getOCCViewer( theViewerId );
if( !aViewer )
return;
+ // Get interactive context
Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
if( aCtx.IsNull() )
return;
-
+ // Get the document
Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( module()->getStudyId() );
if ( !aDoc )
return;
- // Assign Z layer indexes
+ // Assign Z layer indexes to the objects
aDoc->Show( theObjs );
- // TODO: to optimize
// Sort objects by display order ( needed for Z layers assignment only )
- 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 anUnorderedToDisplay = theObjs;
+ HYDROData_SequenceOfObjects anOrderedToDisplay;
+ HYDROData_SequenceOfObjects anAllOrderedObjects = aDoc->GetObjectsLayerOrder();
+
+ HYDROData_SequenceOfObjects::Iterator anAllOrderedIter( anAllOrderedObjects );
+ for ( ; anAllOrderedIter.More(); anAllOrderedIter.Next() ) {
+ QString anOrderedEntry =
+ HYDROGUI_DataObject::dataObjectEntry( anAllOrderedIter.Value() );
- HYDROData_SequenceOfObjects::Iterator aToDisplayIter( anObjectsToDisplay );
+ HYDROData_SequenceOfObjects::Iterator aToDisplayIter( anUnorderedToDisplay );
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 ) );
+ anOrderedToDisplay.Prepend( anObjToDisplay );
+ anUnorderedToDisplay.Remove( aToDisplayIter );
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 3d viewer
+ Handle(V3d_Viewer) aViewer3d = aViewer->getViewer3d();
// Get existing Z layers
TColStd_SequenceOfInteger anExistingZLayers;
- aViewer->getViewer3d()->GetAllZLayers( anExistingZLayers );
+ aViewer3d->GetAllZLayers( anExistingZLayers );
int aNbLayers = anExistingZLayers.Length();
- // Display
+ // Display objects
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;
-
- HYDROGUI_Shape* anObjShape = module()->getObjectShape( (size_t)aViewer, anObj );
- if ( !anObjShape || anObjShape->getIsToUpdate() || theIsForced )
- {
- if ( !anObjShape )
- anObjShape = createShape( (size_t)aViewer, aCtx, anObj );
-
- if ( anObjShape )
- anObjShape->update( false );
+ // 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 ( anObjShape )
- {
- bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
- anObjShape->setVisible( anIsVisible, false );
-
- 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 );
- }
- aNextZLayerIndex++;
- }
+ // 2. Display the unordered objects:
+ bool isDisplayed = false;
+ HYDROData_SequenceOfObjects::Iterator anUnorderedIter( anUnorderedToDisplay );
+ for ( ; anUnorderedIter.More(); anUnorderedIter.Next() ) {
+ Handle(HYDROData_Entity) anObj = anUnorderedIter.Value();
+ if ( Display( anObj, aViewer, theIsForced, aNextZLayerIndex, false ) ) {
+ isDisplayed = true;
}
}
+
+ // 3. Update the top Z layer index
+ if ( isDisplayed ) {
+ aNextZLayerIndex++;
+ }
// Update Z layer of the active operation
+ aViewer3d->GetAllZLayers( anExistingZLayers );
+
HYDROGUI_Module* aModule = module();
SUIT_Operation* anOp = aModule->activeOperation();
HYDROGUI_Operation* aHOp = anOp ? dynamic_cast<HYDROGUI_Operation*>( anOp ) : 0;
}
}
}
- else if ( aCtx.IsNull() )
+ else if ( !aCtx.IsNull() ) // TODO: determine if this code is necessary (added as a fix for issue# 359)
{
aCtx->UpdateSelected();
}
{
return OCCViewer_Viewer::Type();
}
+
+bool HYDROGUI_OCCDisplayer::Display( const Handle(HYDROData_Entity)& theObject,
+ const OCCViewer_Viewer* theViewer,
+ const bool theIsForced,
+ const int theZLayerIndex,
+ const bool theIsOrdered )
+{
+ bool aRes = false;
+
+ if ( theObject.IsNull() || theObject->IsRemoved() || !theViewer ) {
+ return aRes;
+ }
+
+ // Get interactive context
+ Handle(AIS_InteractiveContext) aCtx = theViewer->getAISContext();
+ if( aCtx.IsNull() ) {
+ return aRes;
+ }
+
+ // Viewer id
+ size_t aViewerId = (size_t)theViewer;
+
+ // Object shape
+ HYDROGUI_Shape* anObjShape = module()->getObjectShape( aViewerId, theObject );
+ // create if needed
+ if ( !anObjShape ) {
+ anObjShape = createShape( aViewerId, aCtx, theObject );
+ anObjShape->setIsToUpdate( true );
+ }
+
+ // Process the shape
+ if ( anObjShape ) {
+ // update if needed
+ if ( anObjShape->getIsToUpdate() || theIsForced ) {
+ anObjShape->update( false );
+ }
+
+ // Set visibility
+ 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;
+ }
+ }
+ }
+
+ return aRes;
+}
\ No newline at end of file