2016-01-19 11:17:13 +00:00
# include "instanceselectionmode.hpp"
2016-01-19 13:25:20 +00:00
# include <QMenu>
# include <QAction>
2016-01-25 13:55:02 +00:00
# include "../../model/world/idtable.hpp"
# include "../../model/world/commands.hpp"
2016-01-19 13:25:20 +00:00
# include "worldspacewidget.hpp"
2016-01-25 13:55:02 +00:00
# include "object.hpp"
2016-01-19 13:25:20 +00:00
bool CSVRender : : InstanceSelectionMode : : createContextMenu ( QMenu * menu )
{
if ( menu )
{
menu - > addAction ( mSelectAll ) ;
menu - > addAction ( mDeselectAll ) ;
2016-01-26 10:31:37 +00:00
menu - > addAction ( mSelectSame ) ;
2016-01-25 13:55:02 +00:00
menu - > addAction ( mDeleteSelection ) ;
2016-01-19 13:25:20 +00:00
}
return true ;
}
CSVRender : : InstanceSelectionMode : : InstanceSelectionMode ( CSVWidget : : SceneToolbar * parent ,
WorldspaceWidget & worldspaceWidget )
: CSVWidget : : SceneToolMode ( parent , " Selection Mode " ) , mWorldspaceWidget ( worldspaceWidget )
2016-01-19 11:17:13 +00:00
{
addButton ( " :placeholder " , " cube-centre " ,
" Centred cube "
" <ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection cube outwards</li> "
" <li>The selection cube is aligned to the word space axis</li> "
" <li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li> "
" </ul> "
" <font color=Red>Not implemented yet</font color> " ) ;
addButton ( " :placeholder " , " cube-corner " ,
" Cube corner to corner "
" <ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from one corner of the selection cube to the opposite corner</li> "
" <li>The selection cube is aligned to the word space axis</li> "
" <li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li> "
" </ul> "
" <font color=Red>Not implemented yet</font color> " ) ;
addButton ( " :placeholder " , " sphere " ,
" Centred sphere "
" <ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection sphere outwards</li> "
" <li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li> "
" </ul> "
" <font color=Red>Not implemented yet</font color> " ) ;
2016-01-19 13:25:20 +00:00
2016-01-26 09:51:47 +00:00
mSelectAll = new QAction ( " Select all instances " , this ) ;
2016-01-19 13:25:20 +00:00
mDeselectAll = new QAction ( " Clear selection " , this ) ;
2016-01-26 09:51:47 +00:00
mDeleteSelection = new QAction ( " Delete selected instances " , this ) ;
2016-01-26 10:31:37 +00:00
mSelectSame = new QAction ( " Extend selection to instances with same object ID " , this ) ;
2016-01-19 13:25:20 +00:00
connect ( mSelectAll , SIGNAL ( triggered ( ) ) , this , SLOT ( selectAll ( ) ) ) ;
connect ( mDeselectAll , SIGNAL ( triggered ( ) ) , this , SLOT ( clearSelection ( ) ) ) ;
2016-01-25 13:55:02 +00:00
connect ( mDeleteSelection , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteSelection ( ) ) ) ;
2016-01-26 10:31:37 +00:00
connect ( mSelectSame , SIGNAL ( triggered ( ) ) , this , SLOT ( selectSame ( ) ) ) ;
2016-01-19 13:25:20 +00:00
}
void CSVRender : : InstanceSelectionMode : : selectAll ( )
{
mWorldspaceWidget . selectAll ( Mask_Reference ) ;
}
void CSVRender : : InstanceSelectionMode : : clearSelection ( )
{
mWorldspaceWidget . clearSelection ( Mask_Reference ) ;
2016-01-19 11:17:13 +00:00
}
2016-01-25 13:55:02 +00:00
void CSVRender : : InstanceSelectionMode : : deleteSelection ( )
{
std : : vector < osg : : ref_ptr < TagBase > > selection =
mWorldspaceWidget . getSelection ( Mask_Reference ) ;
CSMWorld : : IdTable & referencesTable =
dynamic_cast < CSMWorld : : IdTable & > ( * mWorldspaceWidget . getDocument ( ) . getData ( ) .
getTableModel ( CSMWorld : : UniversalId : : Type_References ) ) ;
for ( std : : vector < osg : : ref_ptr < TagBase > > : : iterator iter ( selection . begin ( ) ) ;
iter ! = selection . end ( ) ; + + iter )
{
CSMWorld : : DeleteCommand * command = new CSMWorld : : DeleteCommand ( referencesTable ,
static_cast < ObjectTag * > ( iter - > get ( ) ) - > mObject - > getReferenceId ( ) ) ;
mWorldspaceWidget . getDocument ( ) . getUndoStack ( ) . push ( command ) ;
}
}
2016-01-26 10:31:37 +00:00
void CSVRender : : InstanceSelectionMode : : selectSame ( )
{
mWorldspaceWidget . selectAllWithSameParentId ( Mask_Reference ) ;
}