OpenWalnut 1.3.1
|
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 00027 #include "WROI.h" 00028 #include "WPickHandler.h" 00029 00030 WROI::WROI() : 00031 osg::Geode() 00032 { 00033 properties(); 00034 } 00035 00036 WROI::~WROI() 00037 { 00038 } 00039 00040 void WROI::properties() 00041 { 00042 m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) ); 00043 00044 m_active = m_properties->addProperty( "active", "", true, boost::bind( &WROI::propertyChanged, this ) ); 00045 m_active->setHidden( true ); 00046 00047 m_show = m_properties->addProperty( "Show", "Toggles visibility of the roi", true, boost::bind( &WROI::propertyChanged, this ) ); 00048 00049 m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) ); 00050 m_dirty->setHidden( true ); 00051 00052 m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) ); 00053 } 00054 00055 void WROI::propertyChanged() 00056 { 00057 if( m_show->changed() ) 00058 { 00059 if( m_show->get( true ) ) 00060 { 00061 unhide(); 00062 } 00063 else 00064 { 00065 hide(); 00066 } 00067 } 00068 00069 setDirty(); 00070 } 00071 00072 boost::shared_ptr<WProperties> WROI::getProperties() 00073 { 00074 return m_properties; 00075 } 00076 00077 void WROI::setNot( bool isNot ) 00078 { 00079 m_not->set( isNot ); 00080 setDirty(); 00081 } 00082 00083 bool WROI::isNot() 00084 { 00085 return m_not->get(); 00086 } 00087 00088 bool WROI::active() 00089 { 00090 return m_active->get(); 00091 } 00092 00093 void WROI::setActive( bool active ) 00094 { 00095 m_active->set( active ); 00096 setDirty(); 00097 } 00098 00099 void WROI::setDirty() 00100 { 00101 m_dirty->set( true ); 00102 signalRoiChange(); 00103 } 00104 00105 bool WROI::dirty() 00106 { 00107 return m_dirty->get(); 00108 } 00109 00110 void WROI::hide() 00111 { 00112 setNodeMask( 0x0 ); 00113 } 00114 00115 void WROI::unhide() 00116 { 00117 setNodeMask( 0xFFFFFFFF ); 00118 } 00119 00120 void WROI::signalRoiChange() 00121 { 00122 for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin(); 00123 iter != m_changeNotifiers.end(); ++iter ) 00124 { 00125 ( **iter )(); 00126 } 00127 } 00128 00129 void WROI::addROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ) 00130 { 00131 boost::unique_lock< boost::shared_mutex > lock; 00132 lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock ); 00133 m_changeNotifiers.push_back( notifier ); 00134 lock.unlock(); 00135 } 00136 00137 void WROI::removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ) 00138 { 00139 boost::unique_lock< boost::shared_mutex > lock; 00140 lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock ); 00141 std::list< boost::shared_ptr< boost::function< void() > > >::iterator it; 00142 it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier ); 00143 if( it != m_changeNotifiers.end() ) 00144 { 00145 m_changeNotifiers.erase( it ); 00146 } 00147 lock.unlock(); 00148 }