OpenWalnut  1.3.1
WROI.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <list>
26 
27 #include "WROI.h"
28 #include "WPickHandler.h"
29 
30 WROI::WROI() :
31  osg::Geode()
32 {
33  properties();
34 }
35 
37 {
38 }
39 
41 {
42  m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
43 
44  m_active = m_properties->addProperty( "active", "", true, boost::bind( &WROI::propertyChanged, this ) );
45  m_active->setHidden( true );
46 
47  m_show = m_properties->addProperty( "Show", "Toggles visibility of the roi", true, boost::bind( &WROI::propertyChanged, this ) );
48 
49  m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) );
50  m_dirty->setHidden( true );
51 
52  m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
53 }
54 
56 {
57  if( m_show->changed() )
58  {
59  if( m_show->get( true ) )
60  {
61  unhide();
62  }
63  else
64  {
65  hide();
66  }
67  }
68 
69  setDirty();
70 }
71 
72 boost::shared_ptr<WProperties> WROI::getProperties()
73 {
74  return m_properties;
75 }
76 
77 void WROI::setNot( bool isNot )
78 {
79  m_not->set( isNot );
80  setDirty();
81 }
82 
84 {
85  return m_not->get();
86 }
87 
89 {
90  return m_active->get();
91 }
92 
93 void WROI::setActive( bool active )
94 {
95  m_active->set( active );
96  setDirty();
97 }
98 
100 {
101  m_dirty->set( true );
102  signalRoiChange();
103 }
104 
106 {
107  return m_dirty->get();
108 }
109 
111 {
112  setNodeMask( 0x0 );
113 }
114 
116 {
117  setNodeMask( 0xFFFFFFFF );
118 }
119 
121 {
122  for( std::list< boost::shared_ptr< boost::function< void() > > >::iterator iter = m_changeNotifiers.begin();
123  iter != m_changeNotifiers.end(); ++iter )
124  {
125  ( **iter )();
126  }
127 }
128 
129 void WROI::addROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
130 {
131  boost::unique_lock< boost::shared_mutex > lock;
132  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
133  m_changeNotifiers.push_back( notifier );
134  lock.unlock();
135 }
136 
137 void WROI::removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier )
138 {
139  boost::unique_lock< boost::shared_mutex > lock;
140  lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
141  std::list< boost::shared_ptr< boost::function< void() > > >::iterator it;
142  it = std::find( m_changeNotifiers.begin(), m_changeNotifiers.end(), notifier );
143  if( it != m_changeNotifiers.end() )
144  {
145  m_changeNotifiers.erase( it );
146  }
147  lock.unlock();
148 }