OpenWalnut  1.5.0dev
WPropertyBase.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 #include <memory>
27 #include <string>
28 
29 #include <boost/filesystem.hpp>
30 
31 #include "WProperties.h"
32 #include "WPropertyBase.h"
33 #include "WPropertyGroupBase.h"
34 #include "WPropertyVariable.h"
35 #include "WTransferFunction.h"
36 #include "exceptions/WPropertyNameMalformed.h"
37 
38 WPropertyBase::WPropertyBase( std::string name, std::string description ):
39  std::enable_shared_from_this< WPropertyBase >(),
40  m_name( name ),
41  m_description( description ),
42  m_hidden( false ),
43  m_purpose( PV_PURPOSE_PARAMETER ),
44  signal_PropertyChange(),
45  m_updateCondition( new WConditionSet() )
46 {
47  // check name validity
48  if( ( m_name.find( std::string( "/" ) ) != std::string::npos ) || m_name.empty() )
49  {
50  throw WPropertyNameMalformed( std::string( "Property name \"" + name +
51  "\" is malformed. Do not use slashes (\"/\") or empty strings in property names." ) );
52  }
53 }
54 
56  std::enable_shared_from_this< WPropertyBase >(),
57  m_name( from.m_name ),
58  m_description( from.m_description ),
59  m_hidden( from.m_hidden ),
60  m_type( from.m_type ),
61  m_purpose( from.m_purpose ),
62  signal_PropertyChange(), // create a new and empty signal
63  m_updateCondition( new WConditionSet() ) // create a new condition set. Do not copy it.
64 {
65 }
66 
68 {
69  // cleanup
70 }
71 
72 std::string WPropertyBase::getName() const
73 {
74  return m_name;
75 }
76 
77 std::string WPropertyBase::getDescription() const
78 {
79  return m_description;
80 }
81 
82 PROPERTY_TYPE WPropertyBase::getType() const
83 {
84  return m_type;
85 }
86 
87 PROPERTY_PURPOSE WPropertyBase::getPurpose() const
88 {
89  return m_purpose;
90 }
91 
92 void WPropertyBase::setPurpose( PROPERTY_PURPOSE purpose )
93 {
94  m_purpose = purpose;
95 }
96 
98 {
99  m_type = PV_UNKNOWN;
100 }
101 
103 {
104  return m_hidden;
105 }
106 
107 void WPropertyBase::setHidden( bool hidden )
108 {
109  if( m_hidden != hidden )
110  {
111  m_hidden = hidden;
112  m_updateCondition->notify();
113  }
114 }
115 
117 {
118  return std::dynamic_pointer_cast< WPVInt >( shared_from_this() );
119 }
120 
122 {
123  return std::dynamic_pointer_cast< WPVDouble >( shared_from_this() );
124 }
125 
127 {
128  return std::dynamic_pointer_cast< WPVBool >( shared_from_this() );
129 }
130 
132 {
133  return std::dynamic_pointer_cast< WPVString >( shared_from_this() );
134 }
135 
137 {
138  return std::dynamic_pointer_cast< WPVFilename >( shared_from_this() );
139 }
140 
142 {
143  return std::dynamic_pointer_cast< WPVSelection >( shared_from_this() );
144 }
145 
147 {
148  return std::dynamic_pointer_cast< WPVColor >( shared_from_this() );
149 }
150 
152 {
153  return std::dynamic_pointer_cast< WPVPosition >( shared_from_this() );
154 }
155 
157 {
158  return std::dynamic_pointer_cast< WPVGroup >( shared_from_this() );
159 }
160 
162 {
163  return std::dynamic_pointer_cast< WPropertyGroupBase >( shared_from_this() );
164 }
165 
167 {
168  return std::dynamic_pointer_cast< WPVMatrix4X4 >( shared_from_this() );
169 }
170 
172 {
173  return std::dynamic_pointer_cast< WPVTrigger >( shared_from_this() );
174 }
175 
177 {
178  return std::dynamic_pointer_cast< WPVTransferFunction >( shared_from_this() );
179 }
180 
181 std::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
182 {
183  return m_updateCondition;
184 }
185 
187 {
188  return std::dynamic_pointer_cast< WPVInterval >( shared_from_this() );
189 }
190 
Class allowing multiple conditions to be used for one waiting cycle.
Definition: WConditionSet.h:44
Abstract base class for all properties.
Definition: WPropertyBase.h:48
bool isHidden() const
Determines whether the property is hidden or not.
PROPERTY_TYPE m_type
Type of the PropertyVariable instance.
std::shared_ptr< WPropertyGroupBase > toPropGroupBase()
Convert the property to a WPropertyGroupBase.
WPropInterval toPropInterval()
Helper converts this instance to its native type.
WPropString toPropString()
Helper converts this instance to its native type.
WPropDouble toPropDouble()
Helper converts this instance to its native type.
std::string m_description
Description of the property.
WPropTransferFunction toPropTransferFunction()
Helper converts this instance to its native type.
PROPERTY_PURPOSE m_purpose
The purpose of this property.
std::string getName() const
Gets the name of the class.
std::shared_ptr< WConditionSet > m_updateCondition
Condition notified whenever something changes.
WPropBool toPropBool()
Helper converts this instance to its native type.
virtual PROPERTY_TYPE getType() const
Gets the real WPropertyVariable type of this instance.
bool m_hidden
Flag denoting whether the property is hidden or not.
WPropColor toPropColor()
Helper converts this instance to its native type.
void setHidden(bool hidden=true)
Sets the property hidden.
std::string getDescription() const
Gets the description of the property.
std::string m_name
Name of the property.
WPropFilename toPropFilename()
Helper converts this instance to its native type.
virtual std::shared_ptr< WCondition > getUpdateCondition() const
This method returns a condition which gets fired whenever the property changes somehow.
WPropMatrix4X4 toPropMatrix4X4()
Helper converts this instance to its native type.
WPropInt toPropInt()
Helper converts this instance to its native type.
WPropPosition toPropPosition()
Helper converts this instance to its native type.
virtual void setPurpose(PROPERTY_PURPOSE purpose)
Sets the purpose of the property.
WPropertyBase(std::string name, std::string description)
Create an empty named property.
virtual PROPERTY_PURPOSE getPurpose() const
Gets the purpose of a property.
WPropTrigger toPropTrigger()
Helper converts this instance to its native type.
virtual void updateType()
Calculates the type of the property.
WPropSelection toPropSelection()
Helper converts this instance to its native type.
virtual ~WPropertyBase()
Destructor.
WPropGroup toPropGroup()
Helper converts this instance to its native type.
std::shared_ptr< WPropertyGroupBase > SPtr
Convenience typedef for a std::shared_ptr< WPropertyGroupBase >.
Indicates invalid property name.