floatpropertylua.h 7.4 KB
Newer Older
Hossain Mahmud's avatar
Hossain Mahmud committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// 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
// 
// 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.
// 
// ================================================================================================

Hossain Mahmud's avatar
Hossain Mahmud committed
25
26
#ifndef FLOATPROPERTYLUA_H__
#define FLOATPROPERTYLUA_H__
Hossain Mahmud's avatar
Hossain Mahmud committed
27

Hossain Mahmud's avatar
Hossain Mahmud committed
28
29
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
30
#include "core/properties/floatingpointproperty.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
31
#include "core/tools/stringutils.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
32
33
34

namespace campvis {
    /**
Hossain Mahmud's avatar
Hossain Mahmud committed
35
     * Lua for a FloatProperty
Hossain Mahmud's avatar
Hossain Mahmud committed
36
     */
Hossain Mahmud's avatar
Hossain Mahmud committed
37
    class FloatPropertyLua : public AbstractPropertyLua {
Hossain Mahmud's avatar
Hossain Mahmud committed
38
39
    public:
        /**
Hossain Mahmud's avatar
Hossain Mahmud committed
40
41
         * Creates a new FloatPropertyLua for the property \a property.
         * \param   property    The property the Lua shall handle
Hossain Mahmud's avatar
Hossain Mahmud committed
42
         * \param   dataContainer   DataContainer to use (optional), defaults to nullptr.
Hossain Mahmud's avatar
Hossain Mahmud committed
43
         * \param   parent      Parent Qt Lua
Hossain Mahmud's avatar
Hossain Mahmud committed
44
         */
Hossain Mahmud's avatar
Hossain Mahmud committed
45
        FloatPropertyLua(FloatProperty* property, DataContainer* dataContainer);
Hossain Mahmud's avatar
Hossain Mahmud committed
46
47
48
49

        /**
         * Destructor
         */
Hossain Mahmud's avatar
Hossain Mahmud committed
50
        virtual ~FloatPropertyLua();
Hossain Mahmud's avatar
Hossain Mahmud committed
51

Hossain Mahmud's avatar
Hossain Mahmud committed
52
53
        std::string getLuaScript();
        
Hossain Mahmud's avatar
Hossain Mahmud committed
54
55
56
    };

    // explicitly instantiate template, so that it gets registered also over DLL boundaries.
Hossain Mahmud's avatar
Hossain Mahmud committed
57
    template class PropertyLuaRegistrar<FloatPropertyLua, FloatProperty>;
Hossain Mahmud's avatar
Hossain Mahmud committed
58
59
60
61
62

// ================================================================================================

    namespace {
        template<size_t SIZE>
Hossain Mahmud's avatar
Hossain Mahmud committed
63
        struct VecPropertyLuaTraits {};
Hossain Mahmud's avatar
Hossain Mahmud committed
64
65

        template<>
Hossain Mahmud's avatar
Hossain Mahmud committed
66
        struct VecPropertyLuaTraits<2> {
Hossain Mahmud's avatar
Hossain Mahmud committed
67
68
69
70
71
            typedef Vec2Property PropertyType;
            typedef tgt::vec2 BaseType;
        };

        template<>
Hossain Mahmud's avatar
Hossain Mahmud committed
72
        struct VecPropertyLuaTraits<3> {
Hossain Mahmud's avatar
Hossain Mahmud committed
73
74
75
76
77
            typedef Vec3Property PropertyType;
            typedef tgt::vec3 BaseType;
        };

        template<>
Hossain Mahmud's avatar
Hossain Mahmud committed
78
        struct VecPropertyLuaTraits<4> {
Hossain Mahmud's avatar
Hossain Mahmud committed
79
80
81
82
83
84
85
86
            typedef Vec4Property PropertyType;
            typedef tgt::vec4 BaseType;
        };
    }

// ================================================================================================

    /**
Hossain Mahmud's avatar
Hossain Mahmud committed
87
     * Generic base class for Vec property Luas.
Hossain Mahmud's avatar
Hossain Mahmud committed
88
89
90
91
     * Unfortunately Q_OBJECT and templates do not fit together, so we an additional level of 
     * indirection helps as usual...
     */
    template<size_t SIZE>
Hossain Mahmud's avatar
Hossain Mahmud committed
92
    class VecPropertyLua : public AbstractPropertyLua {
Hossain Mahmud's avatar
Hossain Mahmud committed
93
94
    public:
        enum { size = SIZE };
Hossain Mahmud's avatar
Hossain Mahmud committed
95
        typedef typename VecPropertyLuaTraits<SIZE>::PropertyType PropertyType;
Hossain Mahmud's avatar
Hossain Mahmud committed
96
97

        /**
Hossain Mahmud's avatar
Hossain Mahmud committed
98
99
100
         * Creates a new VecPropertyLua for the property \a property.
         * \param   property    The property the Lua shall handle
         * \param   parent      Parent Qt Lua
Hossain Mahmud's avatar
Hossain Mahmud committed
101
         */
Hossain Mahmud's avatar
Hossain Mahmud committed
102
        VecPropertyLua(PropertyType* property, DataContainer* dataContainer = nullptr);
Hossain Mahmud's avatar
Hossain Mahmud committed
103
104
105
106

        /**
         * Destructor
         */
Hossain Mahmud's avatar
Hossain Mahmud committed
107
        virtual ~VecPropertyLua();
Hossain Mahmud's avatar
Hossain Mahmud committed
108

Hossain Mahmud's avatar
Hossain Mahmud committed
109
        virtual std::string getLuaScript();
Hossain Mahmud's avatar
Hossain Mahmud committed
110
111
112
113
114
115

    };

// ================================================================================================

    template<size_t SIZE>
Hossain Mahmud's avatar
Hossain Mahmud committed
116
117
    campvis::VecPropertyLua<SIZE>::VecPropertyLua(PropertyType* property, DataContainer* dataContainer)
        : AbstractPropertyLua(property, true, dataContainer)
Hossain Mahmud's avatar
Hossain Mahmud committed
118
119
120
121
    {
    }

    template<size_t SIZE>
Hossain Mahmud's avatar
Hossain Mahmud committed
122
    campvis::VecPropertyLua<SIZE>::~VecPropertyLua() {
Hossain Mahmud's avatar
Hossain Mahmud committed
123
124
125
126
        PropertyType* property = static_cast<PropertyType*>(_property);
    }

    template<size_t SIZE>
Hossain Mahmud's avatar
Hossain Mahmud committed
127
128
129
130
    std::string campvis::VecPropertyLua<SIZE>::getLuaScript() {
        std::string ret = "-- NOT IMPLEMENTED VecProperty";
        //ret += "getProperty(" + _property->getName() + "):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
        return ret;
Hossain Mahmud's avatar
Hossain Mahmud committed
131
132
133
    }
// ================================================================================================

Hossain Mahmud's avatar
Hossain Mahmud committed
134
    class Vec2PropertyLua : public VecPropertyLua<2> {
Hossain Mahmud's avatar
Hossain Mahmud committed
135
    public:
Hossain Mahmud's avatar
Hossain Mahmud committed
136
137
        Vec2PropertyLua(PropertyType* property, DataContainer* dataContainer = nullptr)
            : VecPropertyLua<2>(property, dataContainer)
Hossain Mahmud's avatar
Hossain Mahmud committed
138
139
140
        {
        }

Hossain Mahmud's avatar
Hossain Mahmud committed
141
142
143
144
145
146
147
        std::string campvis::Vec2PropertyLua::getLuaScript() {
            tgt::vec2 value = static_cast<Vec2Property*>(_property)->getValue();
            std::string ret = "";
            ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec2(" 
                + StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) + "))";
            return ret;
        }
Hossain Mahmud's avatar
Hossain Mahmud committed
148
149
150
151
    }; 

// ================================================================================================
    
Hossain Mahmud's avatar
Hossain Mahmud committed
152
    class Vec3PropertyLua : public VecPropertyLua<3> {
Hossain Mahmud's avatar
Hossain Mahmud committed
153
    public:
Hossain Mahmud's avatar
Hossain Mahmud committed
154
155
        Vec3PropertyLua(PropertyType* property, DataContainer* dataContainer = nullptr)
            : VecPropertyLua<3>(property, dataContainer)
Hossain Mahmud's avatar
Hossain Mahmud committed
156
157
        {
        }
Hossain Mahmud's avatar
Hossain Mahmud committed
158
159
160
        std::string campvis::Vec3PropertyLua::getLuaScript() {
            tgt::vec3 value = static_cast<Vec3Property*>(_property)->getValue();
            std::string ret = "";
161
            ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec3(" 
Hossain Mahmud's avatar
Hossain Mahmud committed
162
163
164
165
                + StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) 
                +", " + StringUtils::toString(value.z) + "))";
            return ret;
        }
Hossain Mahmud's avatar
Hossain Mahmud committed
166
167
168
169
    }; 

// ================================================================================================

Hossain Mahmud's avatar
Hossain Mahmud committed
170
    class Vec4PropertyLua : public VecPropertyLua<4> {
Hossain Mahmud's avatar
Hossain Mahmud committed
171
    public:
Hossain Mahmud's avatar
Hossain Mahmud committed
172
173
        Vec4PropertyLua(PropertyType* property, DataContainer* dataContainer = nullptr)
            : VecPropertyLua<4>(property, dataContainer)
Hossain Mahmud's avatar
Hossain Mahmud committed
174
175
176
        {
        }

Hossain Mahmud's avatar
Hossain Mahmud committed
177
178
179
        std::string campvis::Vec4PropertyLua::getLuaScript() {
            tgt::vec4 value = static_cast<Vec4Property*>(_property)->getValue();
            std::string ret = "";
180
            ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec4(" 
Hossain Mahmud's avatar
Hossain Mahmud committed
181
182
183
184
185
                + StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) +", "
                + StringUtils::toString(value.z) +", " + StringUtils::toString(value.w) + "))";
            return ret;
        }
    };
Hossain Mahmud's avatar
Hossain Mahmud committed
186
187
188
189

// ================================================================================================

    // explicitly instantiate template, so that it gets registered also over DLL boundaries.
Hossain Mahmud's avatar
Hossain Mahmud committed
190
191
192
    template class PropertyLuaRegistrar<Vec2PropertyLua, typename VecPropertyLuaTraits<2>::PropertyType, 5>;
    template class PropertyLuaRegistrar<Vec3PropertyLua, typename VecPropertyLuaTraits<3>::PropertyType, 5>;
    template class PropertyLuaRegistrar<Vec4PropertyLua, typename VecPropertyLuaTraits<4>::PropertyType, 5>;
Hossain Mahmud's avatar
Hossain Mahmud committed
193
194
195

}

Hossain Mahmud's avatar
Hossain Mahmud committed
196
#endif // FLOATPROPERTYLUA_H__