BaseObjectData.hh 14.7 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  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 with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  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.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52




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

/**
53
 * \file BaseObjectData.hh
Jan Möbius's avatar
 
Jan Möbius committed
54
55
56
57
58
59
60
61
 * This File contains the Basic object class for all Objects which show content vi
 * the Scenegraph.
 */


#ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH

62

Jan Möbius's avatar
 
Jan Möbius committed
63
64
//== INCLUDES =================================================================

Jan Möbius's avatar
Jan Möbius committed
65
#include <OpenFlipper/common/GlobalDefines.hh>
66
67
#include <OpenFlipper/common/BaseObject.hh>
#include <QObject>
Jan Möbius's avatar
 
Jan Möbius committed
68
69
70
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
71
#include <ACG/Scenegraph/ShaderNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
72
#include <ACG/Scenegraph/BaseNode.hh>
73
#include <ACG/Scenegraph/BoundingBoxNode.hh>
74
#include <ACG/Scenegraph/StencilRefNode.hh>
75
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
76
77
78
79
80
81
82

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

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
83
typedef ACG::SceneGraph::QtTranslationManipulatorNode     QtTranslationManipulatorNode;
Jan Möbius's avatar
 
Jan Möbius committed
84
85
86
87
/// Seperator Node
typedef ACG::SceneGraph::SeparatorNode                    SeparatorNode;
/// Base Node
typedef ACG::SceneGraph::BaseNode                         BaseNode;
88
89
/// Bounding box Node
typedef ACG::SceneGraph::BoundingBoxNode                  BoundingBoxNode;
90
91
/// Stencil reference Node
typedef ACG::SceneGraph::StencilRefNode                   StencilRefNode;
Jan Möbius's avatar
 
Jan Möbius committed
92
93
94
95
96
97
98
99

//== 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
{
100
101
  Q_OBJECT
  
Jan Möbius's avatar
 
Jan Möbius committed
102
  public:
103
104
105
106
107
108
109

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

Jan Möbius's avatar
 
Jan Möbius committed
110
    /// constructor
111
    BaseObjectData();
Jan Möbius's avatar
 
Jan Möbius committed
112
113
114

    ///destructor
    virtual ~BaseObjectData();
115

Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
  protected:
    /** This function creates the scenegraph nodes */
    virtual void init();
119
120
121

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
122
123
124
  //===========================================================================
  /** @name Data
   * @{ */
125
126
127
  //===========================================================================

  public:
Jan Möbius's avatar
 
Jan Möbius committed
128
    /** Clean all data structures of the object
129
      *
Jan Möbius's avatar
 
Jan Möbius committed
130
131
      * */
    virtual void cleanup();
132
133
134

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
135
136
137
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
138
139
140
141
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
142
143
144
    /** 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
145
     *
Jan Möbius's avatar
 
Jan Möbius committed
146
147
148
     * @param _filename path to the file.
     */
    void setFromFileName(QString _filename );
149

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

Jan Möbius's avatar
 
Jan Möbius committed
153
154
    /// return the path to the object ( defaults to "." if unset )
    QString path();
155

Jan Möbius's avatar
 
Jan Möbius committed
156
    /// set the path to the object.
157
    void setPath(QString _path);
158

Jan Möbius's avatar
 
Jan Möbius committed
159
  private:
160

Jan Möbius's avatar
 
Jan Möbius committed
161
162
    /// path to the file from which the object is loaded ( defaults to "." )
    QString path_;
163
164
165
166
167

  /** @} */



Jan Möbius's avatar
 
Jan Möbius committed
168
169
170
  //===========================================================================
  /** @name Object visualization
   * @{ */
171
172
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
173
174
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
175
    virtual void show();
176

Jan Möbius's avatar
 
Jan Möbius committed
177
    /// Sets the whole Scenegraph subtree of this node to invisible
178
    virtual void hide();
179

180
    /// return visiblity
181
    virtual bool visible();
182
183

    /// Sets visiblity of the whole Scenegraph subtree of this node
184
    virtual void visible(bool _visible);
185

Jan Möbius's avatar
 
Jan Möbius committed
186
187
188
189
    /** 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();
190

191
192
193
194
195
196
197
    /** \brief Check if the given node is owned by this object
    *
    * You can overload this function and return true, if your object generated the given node. 
    * Don't forget to call this baseclass function on overload!
    */
    virtual bool hasNode(BaseNode* _node);
    
Dirk Wilden's avatar
Dirk Wilden committed
198
199
200
201
    /** get the primary node of this object (Use this node to change drawModes)
     */
    virtual BaseNode* primaryNode();
    
Jan Möbius's avatar
 
Jan Möbius committed
202
203
204
    /** 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)
     */
205
    QtTranslationManipulatorNode* manipulatorNode();
206
207
208
209
210
211
212
213

    /** 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
214
215
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
216

217
218
219
    /// get a pointer to the bounding box node
    BoundingBoxNode* boundingBoxNode();

220
221
222
    /// get a pointer to the stencil reference node
    StencilRefNode* stencilRefNode();

Jan Möbius's avatar
 
Jan Möbius committed
223
224
    /// Check if the manipulator has been placed
    bool manipPlaced();
225

Jan Möbius's avatar
 
Jan Möbius committed
226
227
    /// set the manipulator place status
    void manipPlaced( bool _placed );
228
229
230

    /// get the bounding box of the object
    void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
231
    
232
233
    /** \brief Set the draw mode for the object
     * @param _mode  The draw mode that should be active for this object
234
     * @param _force If true, the mode is set ignoring if its supported by the node and its subnodes
235
236
     */
    void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode _mode, bool _force = false);
237

Jan Möbius's avatar
 
Jan Möbius committed
238
239
  private :

240

Jan Möbius's avatar
 
Jan Möbius committed
241
    bool manipPlaced_;
242

Jan Möbius's avatar
 
Jan Möbius committed
243
244
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
245

Jan Möbius's avatar
 
Jan Möbius committed
246
247
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
248
249

    /// Manipulator used for this Object
250
    QtTranslationManipulatorNode*  manipulatorNode_;
251

Jan Möbius's avatar
 
Jan Möbius committed
252
253
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
254

255
256
257
    /// Bounding box node for the object
    BoundingBoxNode * boundingBoxNode_;

258
259
260
    /// Stencil reference node for the object
    StencilRefNode* stencilRefNode_;

261
262
263
  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
264
265
266
  //===========================================================================
  /** @name Picking
   * @{ */
267
268
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
269
270
271
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
272
273
274
275
276
277
278
279
280
281
282
283

    /** 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();
284
285
286

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
287
288
289
290
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
291

Jan Möbius's avatar
 
Jan Möbius committed
292
  public:
Jan Möbius's avatar
Jan Möbius committed
293
294
295
296
297
    /** \brief  This function is called to update the object
    *
    * If the object changes, the core will call this function. Normally this will update
    * the corresponding scenegraph nodes or trigger other data handling which has to be done
    * when the object changes.
Jan Möbius's avatar
Jan Möbius committed
298
299
    *
    * \note Do not call this function yourself to avoid unnecessary overhead(the core will call it when it is required)
Jan Möbius's avatar
Jan Möbius committed
300
    */
301
    virtual void update(UpdateType _type = UPDATE_ALL );
302
303
304

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
305
306
  //===========================================================================
  /** @name Additional nodes
Jan Möbius's avatar
Jan Möbius committed
307
308
309
310
311
   *
   *  \anchor BaseObjectData_AdditionalNodes_header Functions to attach additional Nodes to objects
   *
   *  Manage additional scenegraph nodes that belong to an object.
   *
Jan Möbius's avatar
 
Jan Möbius committed
312
   * @{ */
313
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
314
315
  public:
    /** \brief add an additional node to the object
316
317
    *
    * 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
318
319
    * 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
Jan Möbius's avatar
Jan Möbius committed
320
321
    * new node below the manipulatorNode ( BaseObjectData::manipulatorNode() ) if you want that it moves with the rest of the data. Otherwise
    * add it below the baseNode ( BaseObjectData::baseNode() of the object.
322
    *
Jan Möbius's avatar
 
Jan Möbius committed
323
324
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
325
    *  @param _nodeName Name of the New Node
Jan Möbius's avatar
 
Jan Möbius committed
326
327
328
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
329
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
330
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
331

Jan Möbius's avatar
 
Jan Möbius committed
332
    /** \brief check if an object has the additional node
333
    *
Jan Möbius's avatar
 
Jan Möbius committed
334
335
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
336
    *
Jan Möbius's avatar
 
Jan Möbius committed
337
    *  @param _pluginName Name of the current plugin
338
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
339
340
341
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
342
343
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

Jan Möbius's avatar
 
Jan Möbius committed
344
    /** \brief get an addition node from the object
345
    *
Jan Möbius's avatar
 
Jan Möbius committed
346
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
347
    *
Jan Möbius's avatar
 
Jan Möbius committed
348
349
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
350
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
351
352
353
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
354
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
355
356
357
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
358
    *
Jan Möbius's avatar
Jan Möbius committed
359
360
361
    * If additional nodes are stored for this object, such a node can be removed using this function.
    * If this node has children, they will be removed from the scenegraph as well (and their
    * memory is freed).
362
    *
Jan Möbius's avatar
 
Jan Möbius committed
363
364
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
365
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
366
367
368
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
369
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
370
371
372
373
374
375
    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_;
376
377
378

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
379
380
381
382
383
384
385
386
387
388
389
390
391
};


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

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

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