<commit_before>#include <osgGA/StateSetManipulator>

#include <osg/PolygonMode>

using namespace osg;
using namespace osgGA;

StateSetManipulator::StateSetManipulator(): _drawState(NULL)
{
}

StateSetManipulator::~StateSetManipulator()
{
}

void StateSetManipulator::setStateSet(StateSet *drawState)
{
    _drawState=drawState;
    if(!_drawState.valid()) return;
    _backface = (_drawState->getMode(GL_CULL_FACE)&osg::StateAttribute::ON);
    _lighting =(_drawState->getMode(GL_LIGHTING)&osg::StateAttribute::ON);
    _texture =(_drawState->getTextureMode(0,GL_TEXTURE_2D)&osg::StateAttribute::ON);
}

StateSet *StateSetManipulator::getStateSet()
{
    return _drawState.get();
}

const StateSet *StateSetManipulator::getStateSet() const
{
    return _drawState.get();
}

bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
    if(!_drawState.valid()) return false;

    if(ea.getEventType()==GUIEventAdapter::KEYDOWN)
    {

        switch( ea.getKey() )
        {

            case 'b' :
                _backface = !_backface;
                if( _backface ) _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
                else _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
                aa.requestRedraw();
                return true;
                break;

            case 'l' :
                _lighting = !_lighting ;
                if( _lighting ) _drawState->setMode(GL_LIGHTING,osg::StateAttribute::ON);
                else _drawState->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
                aa.requestRedraw();
                return true;
                break;

            case 't' :
                _texture = !_texture;
                if (_texture) _drawState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::INHERIT);
                else _drawState->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
                aa.requestRedraw();
                return true;
                break;

            case 'w' :
                {
                    osg::PolygonMode* polyModeObj = dynamic_cast<osg::PolygonMode*>(_drawState->getAttribute(osg::StateAttribute::POLYGONMODE));
                    if (!polyModeObj) 
                    {
                        polyModeObj = new osg::PolygonMode;
                        _drawState->setAttribute(polyModeObj);
                    }

                    // cycle through the available modes.  
                    switch(polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK))
                    {
                        case osg::PolygonMode::FILL : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); break;<commit_msg>From <NAME>, addition of support for toggling on and off GL_TEXTURE_1D, 3D, CUBE_MAP and GL_TEXTURE_RECTANGLE (small addition from R.O)<commit_after>#include <osgGA/StateSetManipulator>

#include <osg/PolygonMode>
#include <osg/ref_ptr>
#include <osg/Texture>
#include <osg/Texture2D>
#include <osg/TextureRectangle>

using namespace osg;
using namespace osgGA;

StateSetManipulator::StateSetManipulator(): _drawState(NULL)
{
}

StateSetManipulator::~StateSetManipulator()
{
}

void StateSetManipulator::setStateSet(StateSet *drawState)
{
    _drawState=drawState;
    if(!_drawState.valid()) return;
    _backface = (_drawState->getMode(GL_CULL_FACE)&osg::StateAttribute::ON);
    _lighting =(_drawState->getMode(GL_LIGHTING)&osg::StateAttribute::ON);
    
    unsigned int mode = osg::StateAttribute::INHERIT|osg::StateAttribute::ON;
    _texture = (_drawState->getTextureMode(0,GL_TEXTURE_1D)&mode) ||
               (_drawState->getTextureMode(0,GL_TEXTURE_2D)&mode) ||
               (_drawState->getTextureMode(0,GL_TEXTURE_3D)&mode) ||
               (_drawState->getTextureMode(0,GL_TEXTURE_RECTANGLE)&mode) ||
               (_drawState->getTextureMode(0,GL_TEXTURE_CUBE_MAP)&mode);
}

StateSet *StateSetManipulator::getStateSet()
{
    return _drawState.get();
}

const StateSet *StateSetManipulator::getStateSet() const
{
    return _drawState.get();
}

bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
    if(!_drawState.valid()) return false;

    if(ea.getEventType()==GUIEventAdapter::KEYDOWN)
    {

        switch( ea.getKey() )
        {

            case 'b' :
                _backface = !_backface;
                if( _backface ) _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::ON);
                else _drawState->setMode(GL_CULL_FACE,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
                aa.requestRedraw();
                return true;
                break;

            case 'l' :
                _lighting = !_lighting ;
                if( _lighting ) _drawState->setMode(GL_LIGHTING,osg::StateAttribute::ON);
                else _drawState->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
                aa.requestRedraw();
                return true;
                break;

            case 't' :
            {
                _texture = !_texture;

//                osg::ref_ptr< osg::Texture > tex = dynamic_cast<osg::Texture*>
//                    ( _drawState->getAttribute( osg::StateAttribute::TEXTURE ) );
//                cout << tex->numTextureUnits() << endl;

                unsigned int nunit = 8; // should actually use the _real_ num units here, but how? 
                unsigned int mode = osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF;
                if ( _texture ) mode = osg::StateAttribute::INHERIT|osg::StateAttribute::ON;
                for( unsigned int ii=0; ii<nunit; ii++ )
                {
                        _drawState->setTextureMode( ii, GL_TEXTURE_1D, mode );
                        _drawState->setTextureMode( ii, GL_TEXTURE_2D, mode );
                        _drawState->setTextureMode( ii, GL_TEXTURE_3D, mode );
                        _drawState->setTextureMode( ii, GL_TEXTURE_RECTANGLE, mode );
                        _drawState->setTextureMode( ii, GL_TEXTURE_CUBE_MAP, mode);
                }
                aa.requestRedraw();
                return true;
            }
            break;

            case 'w' :
                {
                    osg::PolygonMode* polyModeObj = dynamic_cast<osg::PolygonMode*>(_drawState->getAttribute(osg::StateAttribute::POLYGONMODE));
                    if (!polyModeObj) 
                    {
                        polyModeObj = new osg::PolygonMode;
                        _drawState->setAttribute(polyModeObj);
                    }

                    // cycle through the available modes.  
                    switch(polyModeObj->getMode(osg::PolygonMode::FRONT_AND_BACK))
                    {
                        case osg::PolygonMode::FILL : polyModeObj->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); break;
{'fraction_non_alphanumeric': 0.11692969870875179, 'fraction_numerical': 0.0031563845050215206, 'mean_word_length': 2.366006760019314, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6794913', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2062, 'n_words': 297}