abstractproperty.h 5.91 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
27
#ifndef ABSTRACTPROPERTY_H__
#define ABSTRACTPROPERTY_H__

schultezub's avatar
schultezub committed
28
#include "sigslot/sigslot.h"
29
30
#include <tbb/atomic.h>
#include <tbb/spin_mutex.h>
schultezub's avatar
schultezub committed
31
#include "tgt/logmanager.h"
32
33

#include "core/coreapi.h"
34
#include "core/pipeline/abstractprocessor.h"
schultezub's avatar
schultezub committed
35

36
#include <set>
schultezub's avatar
schultezub committed
37
38
#include <string>

schultezub's avatar
schultezub committed
39
namespace campvis {
schultezub's avatar
schultezub committed
40
    /**
schultezub's avatar
schultezub committed
41
     * Abstract base class for CAMPVis Property.
schultezub's avatar
schultezub committed
42
     */
43
    class CAMPVIS_CORE_API AbstractProperty {
schultezub's avatar
schultezub committed
44
45
46
47
48
49
    public:
        /**
         * Creates a new AbstractProperty
         * \param name      Property name (unchangable!)
         * \param title     Property title (e.g. used for GUI)
         */
50
        AbstractProperty(const std::string& name, const std::string& title);
schultezub's avatar
schultezub committed
51
52
53
54
55
56
57

        /**
         * Virtual Destructor
         **/
        virtual ~AbstractProperty();


schultezub's avatar
schultezub committed
58
59
60
61
62
63
64
65
66
67
68
69
        /**
         * Initializes the property.
         * Everything that requires a valid OpenGL context or is otherwise expensive gets in here.
         */
        virtual void init();
        
        /**
         * Deinitializes this property.
         * Everything that requires a valid OpenGL context gets in here instead into the dtor.
         */
        virtual void deinit();

schultezub's avatar
schultezub committed
70
71
72
73
        /**
         * Returns the property name.
         * \return  _name
         */
74
        const std::string& getName() const;
schultezub's avatar
schultezub committed
75
76
77
78
79

        /**
         * Returns the property title (e.g. used for GUI).
         * \return  _title
         */
80
        const std::string& getTitle() const;
81
        
82
83
84
85
86
87
88
89
90
91
92
        /**
         * Returns whether this proberty shall be visible in the GUI.
         * \return  _isVisible
         */
        bool isVisible() const;

        /**
         * Sets whether this property shall be visible in the GUI.
         * \param isVisible new visibility flag
         */
        void setVisible(bool isVisible);
schultezub's avatar
schultezub committed
93

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
        /**
         * Adds the given property \a prop to the set of shared properties.
         * All shared properties will be changed when this property changes.
         * Overload in subclasses to make sure that shared properties are of the same type.
         * \note        Make sure not to build circular sharing or you will encounter endless loops!
         * \param prop  Property to add.
         */
        virtual void addSharedProperty(AbstractProperty* prop);

        /**
         * Removes the given property \a prop from the set of shared properties.
         * \param prop  Property to remove.
         */
        void removeSharedProperty(AbstractProperty* prop);

        /**
         * Returns the list of shared properties, which will be changed when this property changes.
         * \note    Property sharing only works in one direction, i.e. shared properties act as child properties.
         *          Make sure not to build circular sharing structures or you will encounter endless loops.
         * \return  _sharedProperties
         */
        const std::set<AbstractProperty*>& getSharedProperties() const;


schultezub's avatar
schultezub committed
118
119
120
121
122
123
124
125
126
127
128
129
130
        /**
         * Locks the property and marks it as "in use". Overwrite if necessary.
         * \sa  AbstractProperty::unlock
         */
        virtual void lock();

        /**
         * Unlocks the property and marks it as "not in use". Overwrite if necessary.
         * \sa  AbstractProperty::lock
         */
        virtual void unlock();


schultezub's avatar
schultezub committed
131
132
133
        /// Signal emitted, when the property changes.
        sigslot::signal1<const AbstractProperty*> s_changed;

134
135
136
        /// Signal emitted, when the visibility of this property changed
        sigslot::signal1<const AbstractProperty*> s_visibilityChanged;

schultezub's avatar
schultezub committed
137
    protected:
schultezub's avatar
schultezub committed
138
        
schultezub's avatar
schultezub committed
139
140
141
        // DO NOT REMOVE THE CONSTNESS OF _name. PropertyCollection relies on it!
        const std::string _name;                ///< Property name (unchangable on purpose!)
        std::string _title;                     ///< Property title (e.g. used for GUI)
142
        tbb::atomic<bool> _isVisible;           ///< Flag whether this property shall be visible in the GUI
schultezub's avatar
schultezub committed
143

144
        tbb::atomic<int> _inUse;                ///< flag whether property is currently in use and values are written to back buffer
schultezub's avatar
schultezub committed
145
146
        tbb::spin_mutex _localMutex;            ///< Mutex used when altering local members

147
148
149
150
151
152
153
        /**
         * List of shared properties that will be changed when this property changes.
         * \note    Property sharing only works in one direction, i.e. shared properties act as child properties.
         *          Make sure not to build circular sharing structures or you will encounter endless loops.
         */
        std::set<AbstractProperty*> _sharedProperties;

154
    private:
schultezub's avatar
schultezub committed
155
156
157
158
159
160
        static const std::string loggerCat_;
    };

}

#endif // ABSTRACTPROPERTY_H__