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 <list> 00026 #include <vector> 00027 00028 #include "../graphicsEngine/WGraphicsEngine.h" 00029 00030 #include "WROIManager.h" 00031 #include "WRMBranch.h" 00032 00033 00034 WRMBranch::WRMBranch( boost::shared_ptr< WROIManager > roiManager ) : 00035 m_roiManager( roiManager ) 00036 { 00037 properties(); 00038 } 00039 00040 WRMBranch::~WRMBranch() 00041 { 00042 } 00043 00044 void WRMBranch::properties() 00045 { 00046 m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This branch's properties" ) ); 00047 00048 m_dirty = m_properties->addProperty( "Dirty", "", true, boost::bind( &WRMBranch::propertyChanged, this ) ); 00049 m_dirty->setHidden( true ); 00050 m_isNot = m_properties->addProperty( "Not", "Negate the effect of this branch.", false, boost::bind( &WRMBranch::propertyChanged, this ) ); 00051 m_bundleColor = m_properties->addProperty( "Bundle color", "", WColor( 1.0, 0.0, 0.0, 1.0 ), 00052 boost::bind( &WRMBranch::propertyChanged, this ) ); 00053 m_changeRoiSignal = boost::shared_ptr< boost::function< void() > >( new boost::function< void() >( boost::bind( &WRMBranch::setDirty, this ) ) ); 00054 } 00055 00056 void WRMBranch::propertyChanged() 00057 { 00058 setDirty(); 00059 } 00060 00061 00062 void WRMBranch::addRoi( osg::ref_ptr< WROI > roi ) 00063 { 00064 m_rois.push_back( roi ); 00065 roi->addROIChangeNotifier( m_changeRoiSignal ); 00066 00067 setDirty(); 00068 } 00069 00070 bool WRMBranch::contains( osg::ref_ptr< WROI > roi ) 00071 { 00072 for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) 00073 { 00074 if( ( *iter ) == roi ) 00075 { 00076 return true; 00077 } 00078 } 00079 return false; 00080 } 00081 00082 void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi ) 00083 { 00084 roi->removeROIChangeNotifier( m_changeRoiSignal ); 00085 for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) 00086 { 00087 if( ( *iter ) == roi ) 00088 { 00089 m_rois.erase( iter ); 00090 setDirty(); 00091 break; 00092 } 00093 } 00094 } 00095 00096 void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT 00097 { 00098 for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) 00099 { 00100 roiVec.push_back( ( *iter ) ); 00101 } 00102 } 00103 00104 void WRMBranch::removeAllRois() 00105 { 00106 for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) 00107 { 00108 WGraphicsEngine::getGraphicsEngine()->getScene()->remove( ( *iter ) ); 00109 } 00110 00111 m_rois.clear(); 00112 } 00113 00114 void WRMBranch::setDirty() 00115 { 00116 m_dirty->set( true ); 00117 m_roiManager->setDirty(); 00118 00119 for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin(); 00120 iter != m_changeNotifiers.end(); ++iter ) 00121 { 00122 ( **iter )(); 00123 } 00124 } 00125 00126 osg::ref_ptr< WROI > WRMBranch::getFirstRoi() 00127 { 00128 return m_rois.front(); 00129 } 00130 00131 boost::shared_ptr< WROIManager > WRMBranch::getRoiManager() 00132 { 00133 return m_roiManager; 00134 } 00135 00136 boost::shared_ptr< WProperties > WRMBranch::getProperties() 00137 { 00138 return m_properties; 00139 } 00140 00141 void WRMBranch::addChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ) 00142 { 00143 boost::unique_lock< boost::shared_mutex > lock; 00144 lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock ); 00145 m_changeNotifiers.push_back( notifier ); 00146 lock.unlock(); 00147 } 00148 00149 void WRMBranch::removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ) 00150 { 00151 boost::unique_lock< boost::shared_mutex > lock; 00152 lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock ); 00153 std::list< boost::shared_ptr< boost::function< void() > > >::iterator it; 00154 it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier ); 00155 if( it != m_changeNotifiers.end() ) 00156 { 00157 m_changeNotifiers.erase( it ); 00158 } 00159 lock.unlock(); 00160 }