OpenWalnut  1.5.0dev
WPropertyWrapper.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 <memory>
26 #include <string>
27 
28 
29 #include "WPropertyWrapper.h"
30 #include "core/common/WProperties.h"
31 
32 WPropertyWrapper::WPropertyWrapper( std::shared_ptr< WPropertyBase > prop )
33  : m_prop( prop )
34 {
35 }
36 
37 std::string WPropertyWrapper::getName() const
38 {
39  return m_prop->getName();
40 }
41 
43 {
44  return m_prop->getDescription();
45 }
46 
47 bool WPropertyWrapper::getBool( bool notify ) const
48 {
49  return m_prop->toPropBool()->get( notify );
50 }
51 
52 int WPropertyWrapper::getInt( bool notify ) const
53 {
54  return m_prop->toPropInt()->get( notify );
55 }
56 
57 std::string WPropertyWrapper::getString( bool notify ) const
58 {
59  return m_prop->toPropString()->get( notify );
60 }
61 
62 double WPropertyWrapper::getDouble( bool notify ) const
63 {
64  return m_prop->toPropDouble()->get( notify );
65 }
66 
67 std::string WPropertyWrapper::getFilename( bool notify ) const
68 {
69  return m_prop->toPropFilename()->get( notify ).string();
70 }
71 
72 int WPropertyWrapper::getSelection( bool notify ) const
73 {
74  return static_cast< int >( m_prop->toPropSelection()->get( notify ).getItemIndexOfSelected( 0 ) );
75 }
76 
78 {
79  WColor c = m_prop->toPropColor()->get( notify );
80  return WColorWrapper( c[ 0 ], c[ 1 ], c[ 2 ], c[ 3 ] );
81 }
82 
84 {
85  m_prop->toPropBool()->set( b, false );
86 }
87 
89 {
90  m_prop->toPropInt()->set( i, false );
91 }
92 
93 void WPropertyWrapper::setString( std::string const& s )
94 {
95  m_prop->toPropString()->set( s, false );
96 }
97 
99 {
100  m_prop->toPropDouble()->set( d, false );
101 }
102 
103 void WPropertyWrapper::setFilename( std::string const& fn )
104 {
105  m_prop->toPropFilename()->set( boost::filesystem::path( fn ), false );
106 }
107 
109 {
111  it.push_back( static_cast< std::size_t >( s ) );
112  WItemSelector sel = m_prop->toPropSelection()->get().newSelector( it );
113  m_prop->toPropSelection()->set( sel, false );
114 }
115 
117 {
118  m_prop->toPropColor()->set( c.get(), false );
119 }
120 
122 {
123  m_prop->toPropTrigger()->set( WPVBaseTypes::PV_TRIGGER_TRIGGERED, false );
124 }
125 
127 {
128  m_prop->getUpdateCondition()->wait();
129 }
Wraps the WColor class for scripts.
Definition: WColorWrapper.h:34
WColor const & get() const
Get the wrapped color.
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:53
std::vector< size_t > IndexList
The type used for storing index lists.
Definition: WItemSelector.h:59
std::shared_ptr< WPropertyBase > m_prop
The property.
std::string getName() const
Return the name of the property.
void setColor(WColorWrapper col)
Set the color of a color property.
void click()
Trigger a trigger property.
void setInt(int i)
Set the value of an integer property.
std::string getString(bool notify=false) const
Get the value of a string property.
std::string getDescription() const
Return the description of the property.
void setString(std::string const &s)
Set the value of a string property.
void setBool(bool b)
Set the value of a boolean property.
WPropertyWrapper(std::shared_ptr< WPropertyBase > prop)
Constructor.
void waitForUpdate()
Wait for the property to update its value.
bool getBool(bool notify=false) const
Get the value of a boolean property.
std::string getFilename(bool notify=false) const
Get the filename of a filename property.
void setFilename(std::string const &fn)
Set the filename of the filename property.
double getDouble(bool notify=false) const
Get the value of a double property.
WColorWrapper getColor(bool notify=false) const
Get the color of a color property.
int getSelection(bool notify=false) const
Get the (first) selected item of a selection property.
void setSelection(int s)
Sets the selected item of a selection.
int getInt(bool notify=false) const
Get the value of an integer property.
void setDouble(double d)
Set the value of a double property.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.