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