BaseObjectData.hh 10.7 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16
17
18
19
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




//=============================================================================
//
//  Types
//
//=============================================================================

/**
42
 * \file BaseObjectData.hh
Jan Möbius's avatar
 
Jan Möbius committed
43
44
45
46
47
48
49
50
 * This File contains the Basic object class for all Objects which show content vi
 * the Scenegraph.
 */


#ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH

51

Jan Möbius's avatar
Jan Möbius committed
52
#ifndef DLLEXPORT
Jan Möbius's avatar
 
Jan Möbius committed
53
54
55
56
57
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
58
#endif
Jan Möbius's avatar
 
Jan Möbius committed
59
60
61
62
63
64
65

//== INCLUDES =================================================================

#include "BaseObject.hh"
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
66
#include <ACG/Scenegraph/ShaderNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
67
#include <ACG/Scenegraph/BaseNode.hh>
68
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
69
70
71
72
73
74
75

//== TYPEDEFS =================================================================

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
76
typedef ACG::SceneGraph::QtTranslationManipulatorNode     QtTranslationManipulatorNode;
Jan Möbius's avatar
 
Jan Möbius committed
77
78
79
80
81
82
83
84
85
86
87
88
89
/// Seperator Node
typedef ACG::SceneGraph::SeparatorNode                    SeparatorNode;
/// Base Node
typedef ACG::SceneGraph::BaseNode                         BaseNode;

//== CLASS DEFINITION =========================================================

/**
 * This is the basic Data class providing the functions common to all objects which show Objects in the SceneGraph
 */
class DLLEXPORT BaseObjectData : public BaseObject
{
  public:
90
91
92
93
94
95
96

    /** \brief copy constructor
     *
     *  Create new basic scenegraph nodes for this object
     */
    BaseObjectData(const BaseObjectData& _object);

Jan Möbius's avatar
 
Jan Möbius committed
97
98
99
100
101
    /// constructor
    BaseObjectData(SeparatorNode* _rootNode);

    ///destructor
    virtual ~BaseObjectData();
102

Jan Möbius's avatar
 
Jan Möbius committed
103
104
105
  protected:
    /** This function creates the scenegraph nodes */
    virtual void init();
106
107
108

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
109
110
111
  //===========================================================================
  /** @name Data
   * @{ */
112
113
114
  //===========================================================================

  public:
Jan Möbius's avatar
 
Jan Möbius committed
115
    /** Clean all data structures of the object
116
      *
Jan Möbius's avatar
 
Jan Möbius committed
117
118
      * */
    virtual void cleanup();
119
120
121

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
122
123
124
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
125
126
127
128
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
129
130
131
    /** Set the object name from a filename. The function will set the name of the
     * object to the filename. At the same time the path is set to the one given in
     * the parameter
132
     *
Jan Möbius's avatar
 
Jan Möbius committed
133
134
135
     * @param _filename path to the file.
     */
    void setFromFileName(QString _filename );
136

Jan Möbius's avatar
 
Jan Möbius committed
137
138
    /// set the name of the object. ( If you overwrite it, call BaseObjectData::setName(_name ) it in your funtion first)
    virtual void setName( QString _name );
139

Jan Möbius's avatar
 
Jan Möbius committed
140
141
    /// return the path to the object ( defaults to "." if unset )
    QString path();
142

Jan Möbius's avatar
 
Jan Möbius committed
143
144
    /// set the path to the object.
    void path(QString _path);
145

Jan Möbius's avatar
 
Jan Möbius committed
146
  private:
147

Jan Möbius's avatar
 
Jan Möbius committed
148
149
    /// path to the file from which the object is loaded ( defaults to "." )
    QString path_;
150
151
152
153
154

  /** @} */



Jan Möbius's avatar
 
Jan Möbius committed
155
156
157
  //===========================================================================
  /** @name Object visualization
   * @{ */
158
159
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
160
161
162
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
    void show();
163

Jan Möbius's avatar
 
Jan Möbius committed
164
165
    /// Sets the whole Scenegraph subtree of this node to invisible
    void hide();
166

Jan Möbius's avatar
 
Jan Möbius committed
167
168
169
170
    /** get the base node of this object (Use this node to add custom Nodes to the Object
     * which should not be transformed with the manipulator of the Object)
     */
    SeparatorNode* baseNode();
171

Jan Möbius's avatar
 
Jan Möbius committed
172
173
174
    /** get the ManipulatorNode node of this object (Use this node to add custom Nodes to the Object
     * which should be transformed with the manipulator of the Object)
     */
175
    QtTranslationManipulatorNode* manipulatorNode();
176
177
178
179
180
181
182
183

    /** Return pointer to the shader node
     * If you want to support shaders, you have to add a shader node into your scenegraph structure
     * above your object to be rendered. If you do not have a shader, just ignore this function
     * and it will return a 0 pointer.
     */
    virtual ACG::SceneGraph::ShaderNode* shaderNode();

Jan Möbius's avatar
 
Jan Möbius committed
184
185
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
186

Jan Möbius's avatar
 
Jan Möbius committed
187
188
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
189

Jan Möbius's avatar
 
Jan Möbius committed
190
191
    /// Check if the manipulator has been placed
    bool manipPlaced();
192

Jan Möbius's avatar
 
Jan Möbius committed
193
194
    /// set the manipulator place status
    void manipPlaced( bool _placed );
195
196
197

    /// get the bounding box of the object
    void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
198

Jan Möbius's avatar
 
Jan Möbius committed
199
200
  private :

201

Jan Möbius's avatar
 
Jan Möbius committed
202
    bool manipPlaced_;
203

Jan Möbius's avatar
 
Jan Möbius committed
204
205
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
206

Jan Möbius's avatar
 
Jan Möbius committed
207
208
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
209
210

    /// Manipulator used for this Object
211
    QtTranslationManipulatorNode*  manipulatorNode_;
212

Jan Möbius's avatar
 
Jan Möbius committed
213
214
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
215
216
217
218

  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
219
220
221
  //===========================================================================
  /** @name Picking
   * @{ */
222
223
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
224
225
226
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
227
228
229
230
231
232
233
234
235
236
237
238

    /** Enable or disable picking for this Node
     * The basic function defined here does nothing.
     * It has to be reimplemented in the derived class
     */
    virtual void enablePicking( bool _enable );

    /** Check if picking is enabled for this Node
     * This function will return true unless the derived class overwrites
     * this function.
     */
    virtual bool pickingEnabled();
239
240
241

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
242
243
244
245
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
246

Jan Möbius's avatar
 
Jan Möbius committed
247
248
249
  public:
    /// This function is called to update the object
    virtual void update();
250
251
252

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
253
254
255
  //===========================================================================
  /** @name Additional nodes
   * @{ */
256
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
257
258
  public:
    /** \brief add an additional node to the object
259
260
    *
    * This function can be used to store an additional Scenegraph node. If you add nodes there, you do not
Jan Möbius's avatar
 
Jan Möbius committed
261
262
    * need to keep track of deleted, added objects, as this will be done in the main application.
    * You have to create the node yourself as this function does not know the type. You should add the
263
    * new node below the manipulatorNode if you want that it moves with the rest of the data. Otherwise
Jan Möbius's avatar
 
Jan Möbius committed
264
    * add it below the seperatorNode of the object.
265
    *
Jan Möbius's avatar
 
Jan Möbius committed
266
267
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
268
    *  @param _nodeName Name of the New Node
Jan Möbius's avatar
 
Jan Möbius committed
269
270
271
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
272
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
273
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
274

Jan Möbius's avatar
 
Jan Möbius committed
275
    /** \brief check if an object has the additional node
276
    *
Jan Möbius's avatar
 
Jan Möbius committed
277
278
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
279
    *
Jan Möbius's avatar
 
Jan Möbius committed
280
    *  @param _pluginName Name of the current plugin
281
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
282
283
284
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
285
286
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

Jan Möbius's avatar
 
Jan Möbius committed
287
    /** \brief get an addition node from the object
288
    *
Jan Möbius's avatar
 
Jan Möbius committed
289
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
290
    *
Jan Möbius's avatar
 
Jan Möbius committed
291
292
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
293
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
294
295
296
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
297
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
298
299
300
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
301
    *
Jan Möbius's avatar
 
Jan Möbius committed
302
    * If additional nodes are stored for this object, such a node can be removed using this function
303
    *
Jan Möbius's avatar
 
Jan Möbius committed
304
305
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
306
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
307
308
309
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
310
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
311
312
313
314
315
316
    bool removeAdditionalNode(NodeT*& _node, QString _pluginName, QString _nodeName , int _id = 0 );
  private:
    /** This pointer may be used to store additional Nodes belonging to this Object
     *   The String should be used by the plugin to identify its Nodes
     */
    std::vector< std::pair <BaseNode*,QString> > additionalNodes_;
317
318
319

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
320
321
322
323
324
325
326
327
328
329
330
331
332
};


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

#if defined(INCLUDE_TEMPLATES) && !defined(BASEOBJECTDATA_C)
#define BASEOBJECT_TEMPLATES
#include "BaseObjectDataT.cc"
#endif

//=============================================================================
#endif // BASEOBJECTDATA_HH defined
//=============================================================================