OpenWalnut  1.4.0
WROI.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <list>
00026 #include <string>
00027 
00028 #include "WROI.h"
00029 #include "WPickHandler.h"
00030 
00031 WROI::WROI():
00032     osg::Geode()
00033 {
00034     properties();
00035 }
00036 
00037 WROI::~WROI()
00038 {
00039 }
00040 
00041 void WROI::properties()
00042 {
00043     m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
00044 
00045     m_name = m_properties->addProperty( "Name", "The name of this ROI.", std::string( "ROI" ) );
00046     m_active = m_properties->addProperty( "Active", "Enable or disable the ROI.", true, boost::bind( &WROI::propertyChanged, this ) );
00047     m_show = m_properties->addProperty( "Show", "Toggles visibility of the ROI but does not disable it.", true,
00048                                         boost::bind( &WROI::propertyChanged, this ) );
00049     m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
00050     m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) );
00051     m_dirty->setHidden( true );
00052 }
00053 
00054 WPropBool WROI::invertProperty()
00055 {
00056     return m_not;
00057 }
00058 
00059 WPropBool WROI::showProperty()
00060 {
00061     return m_show;
00062 }
00063 
00064 WPropString WROI::nameProperty()
00065 {
00066     return m_name;
00067 }
00068 
00069 WPropBool WROI::activeProperty()
00070 {
00071     return m_active;
00072 }
00073 
00074 void WROI::propertyChanged()
00075 {
00076     if( m_show->changed() )
00077     {
00078         if( m_show->get( true ) )
00079         {
00080             unhide();
00081         }
00082         else
00083         {
00084             hide();
00085         }
00086     }
00087 
00088     setDirty();
00089 }
00090 
00091 boost::shared_ptr<WProperties> WROI::getProperties()
00092 {
00093     return m_properties;
00094 }
00095 
00096 void WROI::setNot( bool isNot )
00097 {
00098     m_not->set( isNot );
00099     setDirty();
00100 }
00101 
00102 bool WROI::isNot()
00103 {
00104     return m_not->get();
00105 }
00106 
00107 bool WROI::active()
00108 {
00109     return m_active->get();
00110 }
00111 
00112 void WROI::setActive( bool active )
00113 {
00114     m_active->set( active );
00115     setDirty();
00116 }
00117 
00118 void WROI::setDirty()
00119 {
00120     m_dirty->set( true );
00121     signalRoiChange();
00122 }
00123 
00124 bool WROI::dirty()
00125 {
00126     return m_dirty->get();
00127 }
00128 
00129 void WROI::hide()
00130 {
00131     setNodeMask( 0x0 );
00132 }
00133 
00134 void WROI::unhide()
00135 {
00136     setNodeMask( 0xFFFFFFFF );
00137 }
00138 
00139 void WROI::signalRoiChange()
00140 {
00141     for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin();
00142                 iter != m_changeNotifiers.end(); ++iter )
00143     {
00144         ( **iter )();
00145     }
00146 }
00147 
00148 void WROI::addROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
00149 {
00150     boost::unique_lock< boost::shared_mutex > lock;
00151     lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
00152     m_changeNotifiers.push_back( notifier );
00153     lock.unlock();
00154 }
00155 
00156 void WROI::removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
00157 {
00158     boost::unique_lock< boost::shared_mutex > lock;
00159     lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
00160     std::list<  boost::shared_ptr< boost::function< void() > > >::iterator it;
00161     it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier );
00162     if( it != m_changeNotifiers.end() )
00163     {
00164         m_changeNotifiers.erase( it );
00165     }
00166     lock.unlock();
00167 }