Commit 30ba3684 authored by Frédéric Larue's avatar Frédéric Larue

More than one SelectionManager can now be declared for each Displayable, in...

More than one SelectionManager can now be declared for each Displayable, in order to manage different kind of entities for the same item.
parent 6284ce91
......@@ -36,7 +36,10 @@ void GLViewer::DisplayableInfo::Initialize( DisplayableInterface *displayable,
displayable->boundingBox( this->boundingBox );
this->selectionMgr = displayable->selectionManager();
this->selectionMgr.clear();
displayable->selectionManagers( this->selectionMgr );
currentSelectionMgr = NULL;
}
......@@ -408,8 +411,16 @@ bool GLViewer::addDisplayable( GenericUIData *m )
m->GetDisplayOptions()->show();
}
if( isSelectionEnabled() && dispInfo->selectionMgr )
dispInfo->selectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
if( isSelectionEnabled() )
{
for( auto mngr : dispInfo->selectionMgr )
if( mngr->selectableEntity() == m_SelectionCurrentTool->entityToSelect() )
{
dispInfo->currentSelectionMgr = mngr;
mngr->onRecompilingSelectionShader( m_SelectionCurrentTool );
break;
}
}
updatePrimitiveCounts();
update();
......@@ -449,8 +460,23 @@ void GLViewer::updateDisplayable( GenericUIData *m )
dinfo->displayable->release( *m->GetDisplayOptions() );
dinfo->displayable->initialize( *m->GetDisplayOptions() );
if( isSelectionEnabled() && dinfo->selectionMgr )
dinfo->selectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
// Re-generate the selection managers.
for( auto mngr : dinfo->selectionMgr )
delete mngr;
dinfo->selectionMgr.clear();
dinfo->displayable->selectionManagers( dinfo->selectionMgr );
dinfo->currentSelectionMgr = NULL;
if( isSelectionEnabled() )
{
for( auto mngr : dinfo->selectionMgr )
if( mngr->selectableEntity() == m_SelectionCurrentTool->entityToSelect() )
{
dinfo->currentSelectionMgr = mngr;
mngr->onRecompilingSelectionShader( m_SelectionCurrentTool );
break;
}
}
updatePrimitiveCounts();
update();
......@@ -630,7 +656,10 @@ GLViewer::DisplayableMap::iterator GLViewer::removeDisplayable_Internal( Display
m_DisplayOptionsLayout->removeWidget( item->GetDisplayOptions() );
}
delete dinfo.selectionMgr;
for( auto mngr : dinfo.selectionMgr )
delete mngr;
dinfo.selectionMgr.clear();
dinfo.displayable->release( *item->GetDisplayOptions() );
delete dinfo.displayable;
m_DisplayablesByPriority[ m_Factories[item->GetTypeString()]->displayPriority() ].erase( dinfo.posInPriorityList );
......@@ -997,8 +1026,8 @@ void GLViewer::paintGL()
glPushAttrib( GL_ALL_ATTRIB_BITS );
(*dinfo)->displayable->onDisplay( *(*dinfo)->displayable->getSource()->GetDisplayOptions() );
displayLabel( (*dinfo)->displayable );
if( (*dinfo)->selectionMgr )
(*dinfo)->selectionMgr->onDisplay( this, (*dinfo)->GetTransform() );
if( (*dinfo)->currentSelectionMgr )
(*dinfo)->currentSelectionMgr->onDisplay( this, (*dinfo)->GetTransform() );
glPopAttrib();
glPopMatrix();
}
......@@ -1021,13 +1050,16 @@ void GLViewer::paintGL()
if( dof() == DISPLAY_DOF_3D && m_BelowCursor )
{
double textX, textY;
QVector3D c = m_BelowCursor->GetTransform().map( m_BelowCursor->boundingBox.Center() );
renderCoords( c.x(), c.y(), c.z(), &textX, &textY );
//QVector3D c = m_BelowCursor->GetTransform().map( m_BelowCursor->boundingBox.Center() );
//renderCoords( c.x(), c.y(), c.z(), &textX, &textY );
QPoint c = mapFromGlobal( cursor().pos() );
textX = c.x();
textY = c.y();
QString label = m_BelowCursor->displayable->label();
QFont f( font().family(), 10, QFont::Bold );
Qt::Alignment align = static_cast<Qt::Alignment>( Qt::AlignHCenter | Qt::AlignCenter );
Qt::Alignment align = static_cast<Qt::Alignment>( Qt::AlignHCenter | Qt::AlignTop );
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, label, f, align );
......@@ -1214,11 +1246,11 @@ void GLViewer::updateSelection( SelectionTool &tool )
// Checks every item that can be selected.
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() == tool.entityToSelect() )
if( d->second.currentSelectionMgr )
{
glPushMatrix();
glMultMatrixf( d->second.GetTransform().data() );
d->second.selectionMgr->onUpdatingSelection( &tool );
d->second.currentSelectionMgr->onUpdatingSelection( &tool );
glPopMatrix();
}
......@@ -1368,9 +1400,9 @@ void GLViewer::processSelection( DisplayableInfo &dInfo, BaseSelectionProcessor
{
DisplayableInterface *d = dInfo.displayable;
GenericUIData *m = d->getSource();
SelectionManager *mgr = dInfo.selectionMgr;
SelectionManager *mgr = dInfo.currentSelectionMgr;
if( mgr->selectableEntity() != proc.entityToProcess() )
if( !mgr || mgr->selectableEntity() != proc.entityToProcess() )
return;
QStringList acceptedTypes;
......@@ -1650,7 +1682,7 @@ void GLViewer::findObjectUnderCursor( const QPoint& cursor )
if( getPickedPoint( cursor.x(), height()-cursor.y(), pp, true ) )
{
auto disp = &m_Displayables[ pp.srcObject ];
if( disp != m_BelowCursor )
//if( disp != m_BelowCursor )
{
m_BelowCursor = disp;
update();
......@@ -1784,16 +1816,16 @@ bool GLViewer::event( QEvent *evt )
m_SelectionCurrentTool->onEnabled();
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() == m_SelectionCurrentTool->entityToSelect() )
d->second.selectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
if( d->second.currentSelectionMgr )
d->second.currentSelectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
}
if( kevt->modifiers() & Qt::Modifier::CTRL )
{
int availableEntities = 0;
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr )
availableEntities |= d->second.selectionMgr->selectableEntity();
for( auto mngr : d->second.selectionMgr )
availableEntities |= mngr->selectableEntity();
if( availableEntities )
{
......@@ -2448,8 +2480,8 @@ void GLViewer::setSelectionEnabled( bool enabled )
{
int availableEntities = 0;
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr )
availableEntities |= d->second.selectionMgr->selectableEntity();
for( auto mngr : d->second.selectionMgr )
availableEntities |= mngr->selectableEntity();
if( !availableEntities )
return;
......@@ -2457,6 +2489,8 @@ void GLViewer::setSelectionEnabled( bool enabled )
int newEntity = m_SelectionCurrentTool->entityToSelect();
while( !(newEntity & availableEntities) )
newEntity = (newEntity&4)? 1 : (newEntity << 1);
setSelectionEntity( SelectableEntity::SELECTABLE_ENTITY_NONE );
setSelectionEntity( (SelectableEntity) newEntity );
}
......@@ -2470,8 +2504,7 @@ void GLViewer::setSelectionEnabled( bool enabled )
{
if( d->first->GetDisplayOptions() )
d->first->GetDisplayOptions()->setDisabled( true );
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() == m_SelectionCurrentTool->entityToSelect() )
d->second.selectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
setSelectionEntity( m_SelectionCurrentTool->entityToSelect() );
}
updateSelectionZBuffer();
......@@ -2516,8 +2549,16 @@ void GLViewer::setSelectionEntity( SelectableEntity entity )
m_SelectionCurrentTool->setEntityToSelect( entity );
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() == m_SelectionCurrentTool->entityToSelect() )
d->second.selectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
{
d->second.currentSelectionMgr = NULL;
for( auto mngr : d->second.selectionMgr )
if( mngr->selectableEntity() == entity )
{
d->second.currentSelectionMgr = mngr;
d->second.currentSelectionMgr->onRecompilingSelectionShader( m_SelectionCurrentTool );
break;
}
}
update();
}
......@@ -2529,8 +2570,8 @@ void GLViewer::clearSelection( SelectableEntity entities )
makeCurrent();
for( DisplayableMap::iterator d=m_Displayables.begin(); d!=m_Displayables.end(); ++d )
if( d->second.selectionMgr && d->second.selectionMgr->selectableEntity() & entities )
d->second.selectionMgr->clearSelection();
if( d->second.currentSelectionMgr )
d->second.currentSelectionMgr->clearSelection();
}
......
......@@ -83,7 +83,8 @@ protected:
inline const QMatrix4x4& GetTransform() const { return fullTransform; }
DisplayableInterface *displayable;
SelectionManager *selectionMgr;
QVector<SelectionManager*> selectionMgr;
SelectionManager* currentSelectionMgr;
DisplayableList::iterator posInPriorityList;
Box3f boundingBox;
};
......
......@@ -119,8 +119,6 @@ public:
virtual void onPicking( UIParamSet &params,
GPU::Shader &pickingShader,
const std::string& pickingShaderVertexAttrib ) {}
/** Recover the manager describing the selection behaviour of this item. */
virtual SelectionManager* selectionManager() { return NULL; }
/** Specify if this item can be animated. */
virtual bool isAnimated() { return false; }
......@@ -139,6 +137,9 @@ public:
inline bool isAnimationPaused() const { return m_IsAnimationPaused; }
/** Recover the managers describing the selection behaviour for every kind of selectable entity. */
virtual void selectionManagers( QVector<SelectionManager*> &mngr ) {}
/** Apply a functor to every selected entity. */
virtual void processSelection( SelectionManager *mngr, BaseSelectionProcessor &proc ) {}
signals:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment